package io.wdb.modules.generator.generator.service.impl;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import io.wdb.common.utils.DateFormatUtil;
import io.wdb.modules.generator.generator.dao.AccountCashLogDao;
import io.wdb.modules.generator.generator.dao.BookEntityDao;
import io.wdb.modules.generator.generator.dao.BookgridInfoDao;
import io.wdb.modules.generator.generator.dao.OrderTransDao;
import io.wdb.modules.generator.generator.dao.StatementDao;
import io.wdb.modules.generator.generator.dao.StatisticsDao;
import io.wdb.modules.generator.generator.dao.UserChargeLogDao;
import io.wdb.modules.generator.generator.dao.UserInfoDao;
import io.wdb.modules.generator.generator.dao.VipMemberDao;
import io.wdb.modules.generator.generator.dao.VipMemberLogDao;
import io.wdb.modules.generator.generator.entity.BookgridInfoEntity;
import io.wdb.modules.generator.generator.entity.StatementEntity;
import io.wdb.modules.generator.generator.entity.StatisticsEntity;
import io.wdb.modules.generator.generator.entity.statistics.BookShelfEntityBorrow;
import io.wdb.modules.generator.generator.entity.statistics.BorrowStatistics;
import io.wdb.modules.generator.generator.entity.statistics.CapitalStatistics;
import io.wdb.modules.generator.generator.entity.statistics.UserStatistics;
import io.wdb.modules.generator.generator.entity.statistics.VipStatistics;
import io.wdb.modules.generator.generator.entity.web.DaysQueryRequest;
import io.wdb.modules.generator.generator.entity.web.OperationResponse;
import io.wdb.modules.generator.generator.entity.web.UserOperationCurveResponse;
import io.wdb.modules.generator.generator.service.StatementService;

@Service
public class StatementServiceImpl implements StatementService{
	
	@Autowired
	private StatementDao statementDao;
	
	@Autowired
	private UserInfoDao userInfoDao;
	
	@Autowired
	private AccountCashLogDao accountCashLogDao;
	
	@Autowired
	private UserChargeLogDao userChargeLogDao;
	
	@Autowired
	private OrderTransDao orderTransDao;
	
	@Autowired
	private StatisticsDao statisticsDao;
	
	@Autowired
	private VipMemberLogDao vipMemberLogDao;
	
	@Autowired
	private VipMemberDao vipMemberDao;
	
	@Autowired
	private BookgridInfoDao bookgridInfoDao;
	
	@Autowired
	private BookEntityDao bookEntityDao;
	
	@Override
	public List<StatementEntity> getPassengerRule(Map<String, Object> params) {
		//计算需要拉取的条数以及其他逻辑处理
		return statementDao.getPassengerRule(params);
	}

	@Override
	public int getOrdersByTime(Map<String, Object> params) {
		// TODO Auto-generated method stub
		return statementDao.getOrdersByTime(params);
	}
	
	@Override
	public int getAccountCashByTime(Map<String, Object> params) {
		// TODO Auto-generated method stub
		return statementDao.getAccountCashByTime(params);
	}
	public int getNewUserRiseByTime(Map<String,Object> params){
		return statementDao.getNewUserRiseByTime(params);
	}

	@Override
	public List<OperationResponse> totalStatistics() {
		DaysQueryRequest daysQueryRequest = new DaysQueryRequest();
		Date startTime = DateFormatUtil.parseDate("2017-08-01");
		daysQueryRequest.setQueryStartTime(startTime);
		daysQueryRequest.setOriginalQueryStartTime(startTime);
		
		daysQueryRequest.setQueryEndTime(new Date());
		daysQueryRequest.setOriginalQueryEndTime(new Date());
		daysQueryRequest.setGroupCondition("0");
		
		List<OperationResponse> operationResponses = new ArrayList<OperationResponse>();
		//累计注册用户
		UserStatistics totalUser = userInfoDao.daysUser(daysQueryRequest);//queryTotal();
		OperationResponse totalUserOperation = new OperationResponse();
		totalUserOperation.setKey("注册用户");
		totalUserOperation.setValue(totalUser.getAddUser());
		operationResponses.add(totalUserOperation);
		//累计有效押金
		CapitalStatistics totalDeposit = userChargeLogDao.daysAvailableDeposit(daysQueryRequest);//totalDeposit();
		OperationResponse totalDepositOperation = new OperationResponse();
		totalDepositOperation.setKey("有效押金");
		totalDepositOperation.setValue(totalDeposit.getAvailableDeposit());
		operationResponses.add(totalDepositOperation);
		//累计充余额
		CapitalStatistics totalCash = userChargeLogDao.daysCash(daysQueryRequest);//totalCash();
		OperationResponse totalCashOperation = new OperationResponse();
		totalCashOperation.setKey("充值余额(实际)");
		totalCashOperation.setValue(totalCash.getCash());
		operationResponses.add(totalCashOperation);
		//累计出借书籍
		BorrowStatistics totalBorrowedBooks = orderTransDao.daysBorrowBooks(daysQueryRequest);//totalBorrowedBooks();
		OperationResponse totalBorrowedBooksOperation = new OperationResponse();
		totalBorrowedBooksOperation.setKey("出借书籍");
		totalBorrowedBooksOperation.setValue(totalBorrowedBooks.getBorrowBooks());
		operationResponses.add(totalBorrowedBooksOperation);
		//累计月卡会员
		VipStatistics totalVipMonthUsers = vipMemberDao.daysAvailableVipMonth(daysQueryRequest);//totalVipMonthUsers();
		OperationResponse totalVipMonthUsersOperation = new OperationResponse();
		totalVipMonthUsersOperation.setKey("月卡会员");
		totalVipMonthUsersOperation.setValue(totalVipMonthUsers.getVipAvailableMonthUsers());
		operationResponses.add(totalVipMonthUsersOperation);
		//累计年卡会员
		VipStatistics totalVipYearUsers = vipMemberDao.daysAvailableVipYear(daysQueryRequest);//totalVipYearUsers();
		OperationResponse totalVipYearUsersOperation = new OperationResponse();
		totalVipYearUsersOperation.setKey("年卡会员");
		totalVipYearUsersOperation.setValue(totalVipYearUsers.getVipAvailableYearUsers());
		operationResponses.add(totalVipYearUsersOperation);
		//月卡收入
		VipStatistics totalVipCashMonth = vipMemberLogDao.daysVipAvailableCashMonth(daysQueryRequest);//daysTotalVipCashMonth
		OperationResponse totalVipCashMonthOperation = new OperationResponse();
		totalVipCashMonthOperation.setKey("月卡收入");
		totalVipCashMonthOperation.setValue(totalVipCashMonth.getVipAvailableMonthCash());
		operationResponses.add(totalVipCashMonthOperation);
		//年卡收入
		VipStatistics totalVipCashYear = vipMemberLogDao.daysVipAvailableCashYear(daysQueryRequest);//daysTotalVipCashMonth
		OperationResponse totalVipCashYearOperation = new OperationResponse();
		totalVipCashYearOperation.setKey("年卡收入");
		totalVipCashYearOperation.setValue(totalVipCashYear.getVipAvailableYearCash());
		operationResponses.add(totalVipCashYearOperation);
		//总计借阅用户
		BorrowStatistics totalBorrowedUser = orderTransDao.daysBorrowUsers(daysQueryRequest);//totalBorrowedUser();
		OperationResponse totalBorrowedUserOperation = new OperationResponse();
		totalBorrowedUserOperation.setKey("借阅用户");
		totalBorrowedUserOperation.setValue(totalBorrowedUser.getBorrowUsers());
		operationResponses.add(totalBorrowedUserOperation);
		//总计有效押金用户
		CapitalStatistics totalAvailDepositUser = userChargeLogDao.daysAvailableDepositUser(daysQueryRequest);//totalAvailDepositUser();
		OperationResponse totalAvailDepositUserOperation = new OperationResponse();
		totalAvailDepositUserOperation.setKey("有效押金用户");
		totalAvailDepositUserOperation.setValue(totalAvailDepositUser.getAvailableDepositUser());
		operationResponses.add(totalAvailDepositUserOperation);
		//总计充值用户
		CapitalStatistics totalCashUser = userChargeLogDao.daysCashUser(daysQueryRequest);//totalCashUser
		OperationResponse totalCashUserOperation = new OperationResponse();
		totalCashUserOperation.setKey("充值用户");
		totalCashUserOperation.setValue(totalCashUser.getCashUser());
		operationResponses.add(totalCashUserOperation);
		//总计退押金用户
		CapitalStatistics totalRefundDepositUser = userChargeLogDao.daysRefundDepositUser(daysQueryRequest);//totalRefundDepositUser();
		OperationResponse totalRefundDepositUserOperation = new OperationResponse();
		totalRefundDepositUserOperation.setKey("退押金用户");
		totalRefundDepositUserOperation.setValue(totalRefundDepositUser.getRefundDepositUser());
		operationResponses.add(totalRefundDepositUserOperation);
		//总计退押金
		CapitalStatistics totalRefundDeposit = userChargeLogDao.daysRefundDeposit(daysQueryRequest);//totalRefundDeposit();
		OperationResponse totalRefundDepositOperation = new OperationResponse();
		totalRefundDepositOperation.setKey("退押金");
		totalRefundDepositOperation.setValue(totalRefundDeposit.getRefundDeposit());
		operationResponses.add(totalRefundDepositOperation);
		return operationResponses;
	}

	@Override
	public List<OperationResponse> currentDayStatistics(DaysQueryRequest daysQueryRequest) {
		Date date = new Date();
		daysQueryRequest.setQueryEndTime(date);
		String timeStr = DateFormatUtil.formatDate(daysQueryRequest.getQueryEndTime());
		Date startTime = DateFormatUtil.parseDate(timeStr);
		daysQueryRequest.setQueryStartTime(startTime);
		daysQueryRequest.setGroupCondition("0");
		
		List<OperationResponse> operationResponses = new ArrayList<OperationResponse>();
		//List<StatisticsEntity> statisticsEntitys = statisticsDao.selectDaysStatistics(daysQueryRequest);
		UserStatistics  daysUser = userInfoDao.daysUser(daysQueryRequest);
		OperationResponse dayUserOperation = new OperationResponse();
		dayUserOperation.setKey("注册用户");
		dayUserOperation.setValue(daysUser.getAddUser());
		operationResponses.add(dayUserOperation);
		
		//今日新增有效押金
		CapitalStatistics dayDeposit = userChargeLogDao.daysAvailableDeposit(daysQueryRequest);//currentDayDeposit
		OperationResponse dayDepositOperation = new OperationResponse();
		dayDepositOperation.setKey("有效押金");
		dayDepositOperation.setValue(dayDeposit.getAvailableDeposit());
		operationResponses.add(dayDepositOperation);
		
		CapitalStatistics cashStatistics = userChargeLogDao.daysCash(daysQueryRequest);
		OperationResponse dayCashOperation = new OperationResponse();
		dayCashOperation.setKey("充值余额(实际)");
		dayCashOperation.setValue(cashStatistics.getCash());
		operationResponses.add(dayCashOperation);
		
		BorrowStatistics dayBorrowBooks = orderTransDao.daysBorrowBooks(daysQueryRequest);//currentDayBorrowBooks
		OperationResponse dayBorrowedBooksOperation = new OperationResponse();
		dayBorrowedBooksOperation.setKey("出借书籍");
		dayBorrowedBooksOperation.setValue(dayBorrowBooks.getBorrowBooks());
		operationResponses.add(dayBorrowedBooksOperation);
		//新增月卡会员
		VipStatistics totalVipMonthUsers = vipMemberDao.daysAvailableVipMonth(daysQueryRequest);
		OperationResponse totalVipMonthUsersOperation = new OperationResponse();
		totalVipMonthUsersOperation.setKey("月卡会员");
		totalVipMonthUsersOperation.setValue(totalVipMonthUsers.getVipAvailableMonthUsers());
		operationResponses.add(totalVipMonthUsersOperation);
		//新增年卡会员
		VipStatistics totalVipYearUsers = vipMemberDao.daysAvailableVipYear(daysQueryRequest);
		OperationResponse totalVipYearUsersOperation = new OperationResponse();
		totalVipYearUsersOperation.setKey("年卡会员");
		totalVipYearUsersOperation.setValue(totalVipYearUsers.getVipAvailableYearUsers());
		operationResponses.add(totalVipYearUsersOperation);
		//月卡收入
		VipStatistics totalVipCashMonth = vipMemberLogDao.daysVipAvailableCashMonth(daysQueryRequest);
		OperationResponse totalVipCashMonthOperation = new OperationResponse();
		totalVipCashMonthOperation.setKey("月卡收入");
		totalVipCashMonthOperation.setValue(totalVipCashMonth.getVipAvailableMonthCash());
		operationResponses.add(totalVipCashMonthOperation);
		//年卡收入
		VipStatistics totalVipCashYear = vipMemberLogDao.daysVipAvailableCashYear(daysQueryRequest);
		OperationResponse totalVipCashYearOperation = new OperationResponse();
		totalVipCashYearOperation.setKey("年卡收入");
		totalVipCashYearOperation.setValue(totalVipCashYear.getVipAvailableYearCash());
		operationResponses.add(totalVipCashYearOperation);
		
		BorrowStatistics dayBorrowedUser = orderTransDao.daysBorrowUsers(daysQueryRequest);
		OperationResponse dayBorrowedUserOperation = new OperationResponse();
		dayBorrowedUserOperation.setKey("借阅用户");
		dayBorrowedUserOperation.setValue(dayBorrowedUser.getBorrowUsers());
		operationResponses.add(dayBorrowedUserOperation);
		
		//今日新增有效押金人员
		CapitalStatistics dyaDepositUser = userChargeLogDao.daysAvailableDepositUser(daysQueryRequest);//currentDayDepositUser
		OperationResponse dayDepositUserOperation = new OperationResponse();
		dayDepositUserOperation.setKey("有效押金用户");
		dayDepositUserOperation.setValue(dyaDepositUser.getAvailableDepositUser());
		operationResponses.add(dayDepositUserOperation);
		
		CapitalStatistics dayCashUser = userChargeLogDao.daysCashUser(daysQueryRequest);
		OperationResponse dayCashUserOperation = new OperationResponse();
		dayCashUserOperation.setKey("充值用户");
		dayCashUserOperation.setValue(dayCashUser.getCashUser());
		operationResponses.add(dayCashUserOperation);
		
		
		CapitalStatistics dayRefundDepositUser = userChargeLogDao.daysRefundDepositUser(daysQueryRequest);//currentDayRefundDepositUser
		OperationResponse dayRefundDepositUserOperation = new OperationResponse();
		dayRefundDepositUserOperation.setKey("退押金用户");
		dayRefundDepositUserOperation.setValue(dayRefundDepositUser.getRefundDepositUser());
		operationResponses.add(dayRefundDepositUserOperation);
		
		CapitalStatistics dayRefundDeposit = userChargeLogDao.daysRefundDeposit(daysQueryRequest);//currentDayRefundDeposit
		OperationResponse dayRefundDepositOperation = new OperationResponse();
		dayRefundDepositOperation.setKey("退押金");
		dayRefundDepositOperation.setValue(dayRefundDeposit.getRefundDeposit());
		operationResponses.add(dayRefundDepositOperation);
		
		return operationResponses;
	}

	@Override
	public List<OperationResponse> daysUserTotalStatistics(DaysQueryRequest daysQueryRequest) {
		//判断时间是否为天；
		long diff = daysQueryRequest.getQueryEndTime().getTime() - daysQueryRequest.getQueryStartTime().getTime();
		//判断是否真的小于1天
		String dateStartStr = DateFormatUtil.formatDate(daysQueryRequest.getQueryStartTime());
		String dateEndStr = DateFormatUtil.formatDate(daysQueryRequest.getQueryEndTime());
		this.initQueryRequest(daysQueryRequest);
		long days = diff / (1000 * 60 * 60 * 24)+1;  
		if(days<1) {
			if(dateStartStr.equals(dateEndStr)) {
				days = 1;
			}else {
				days = 2;
			}
		}
		daysQueryRequest.setGroupCondition("1");
		List<OperationResponse> operationResponses = new ArrayList<OperationResponse>();
		BigDecimal daysUsersTotalBig = new BigDecimal("0");
		BigDecimal daysAvailableDepisitUsersTotalBig = new BigDecimal("0");
		BigDecimal daysCashUsersTotalBig = new BigDecimal("0");
		BigDecimal daysVipMonthUserTotalBig = new BigDecimal("0");
		BigDecimal daysVipYearUsersTotalBig = new BigDecimal("0");
		BigDecimal daysRefundDepositUsersTotalBig = new BigDecimal("0");
		BigDecimal daysBorrowUsersTotalBig = new BigDecimal("0");
		for(int i=0;i<days;i++) {
			this.caculateTimeDetailEachQueryRequest(daysQueryRequest, i);
			//注册用户
			UserStatistics daysUser = userInfoDao.daysUser(daysQueryRequest);
			daysUsersTotalBig = daysUsersTotalBig.add(new BigDecimal(daysUser.getAddUser()));
			//有效押金用户
			CapitalStatistics daysAvailableDepositUser = userChargeLogDao.daysAvailableDepositUser(daysQueryRequest);//daysTotalDepositUser
			daysAvailableDepisitUsersTotalBig = daysAvailableDepisitUsersTotalBig.add(new BigDecimal(daysAvailableDepositUser.getAvailableDepositUser()));
			//充值用户
			CapitalStatistics daysCashUser = userChargeLogDao.daysCashUser(daysQueryRequest);
			daysCashUsersTotalBig = daysCashUsersTotalBig.add(new BigDecimal(daysCashUser.getCashUser()));
			//月卡会员
			VipStatistics vipMonthUserStatistics = vipMemberDao.daysVipMonth(daysQueryRequest);
			daysVipMonthUserTotalBig = daysVipMonthUserTotalBig.add(new BigDecimal(vipMonthUserStatistics.getVipMonthUsers()));
			//年卡会员
			VipStatistics vipYearUserStatistics = vipMemberDao.daysVipYear(daysQueryRequest);
			daysVipYearUsersTotalBig = daysVipYearUsersTotalBig.add(new BigDecimal(vipYearUserStatistics.getVipYearUsers()));
			//退押金用户
			CapitalStatistics dayRefundDepositUser = userChargeLogDao.daysRefundDepositUser(daysQueryRequest);//daysTotalRefundDepositUser
			daysRefundDepositUsersTotalBig = daysRefundDepositUsersTotalBig.add(new BigDecimal(dayRefundDepositUser.getRefundDepositUser()));
			//借阅用户
			BorrowStatistics borrowStatistics = orderTransDao.daysBorrowUsers(daysQueryRequest);
			daysBorrowUsersTotalBig = daysBorrowUsersTotalBig.add(new BigDecimal(borrowStatistics.getBorrowUsers()));
		}
		OperationResponse dayUserOperation = new OperationResponse();
		dayUserOperation.setKey("注册用户");
		dayUserOperation.setValue(daysUsersTotalBig.toString());
		operationResponses.add(dayUserOperation);
		
		//指定日期有效押金人员
		//CapitalStatistics dyaDepositUser = userChargeLogDao.daysAvailableDepositUser(daysQueryRequest);//daysTotalDepositUser
		OperationResponse dayDepositUserOperation = new OperationResponse();
		dayDepositUserOperation.setKey("有效押金用户");
		dayDepositUserOperation.setValue(daysAvailableDepisitUsersTotalBig.toString());
		operationResponses.add(dayDepositUserOperation);
		
		OperationResponse dayCashUserOperation = new OperationResponse();
		dayCashUserOperation.setKey("充值用户");
		dayCashUserOperation.setValue(daysCashUsersTotalBig.toString());
		operationResponses.add(dayCashUserOperation);
		
		//VipStatistics vipMonthUserStatistics = vipMemberDao.daysVipMonth(daysQueryRequest);
		OperationResponse vipMonthUserOperation = new OperationResponse();
		vipMonthUserOperation.setKey("月卡会员");
		vipMonthUserOperation.setValue(daysVipMonthUserTotalBig.toString());
		operationResponses.add(vipMonthUserOperation);
		
		//VipStatistics vipYearUserStatistics = vipMemberDao.daysVipYear(daysQueryRequest);
		OperationResponse vipYearUserOperation = new OperationResponse();
		vipYearUserOperation.setKey("年卡会员");
		vipYearUserOperation.setValue(daysVipYearUsersTotalBig.toString());
		operationResponses.add(vipYearUserOperation);
		
		//CapitalStatistics dayRefundDepositUser = userChargeLogDao.daysRefundDepositUser(daysQueryRequest);//daysTotalRefundDepositUser
		OperationResponse dayRefundDepositUserOperation = new OperationResponse();
		dayRefundDepositUserOperation.setKey("退押金用户");
		dayRefundDepositUserOperation.setValue(daysRefundDepositUsersTotalBig.toString());
		operationResponses.add(dayRefundDepositUserOperation);
		
		OperationResponse dayBorrowedUserOperation = new OperationResponse();
		dayBorrowedUserOperation.setKey("借阅用户(活跃用户)");
		dayBorrowedUserOperation.setValue(daysBorrowUsersTotalBig.toString());
		operationResponses.add(dayBorrowedUserOperation);
		
		return operationResponses;
	}
	/**
	 * 
	 * @Method:initQueryRequest
	 * @Description:补充截止时间并记录最初上传时间；
	 * @Time 2018年2月27日 下午4:37:44
	 * @author: Tom
	 * @param daysQueryRequest
	 * @return
	 */
	private DaysQueryRequest initQueryRequest(DaysQueryRequest daysQueryRequest) {
		Date date = new Date();
		Date queryEndTime = daysQueryRequest.getQueryEndTime();
		if(queryEndTime==null) {
			queryEndTime = date;
			daysQueryRequest.setQueryEndTime(date);
		}
		Date originalQueryEndTime = daysQueryRequest.getQueryEndTime();
		daysQueryRequest.setOriginalQueryEndTime(originalQueryEndTime);
		
		Date originalQueryStartTime = daysQueryRequest.getQueryStartTime();
		daysQueryRequest.setOriginalQueryStartTime(originalQueryStartTime);
		return daysQueryRequest;
	}
	/**
	 * 
	 * @Method:calculateEachQueryRequest
	 * @Description:
	 * @Time 2018年2月26日 下午6:04:39
	 * @author: Tom
	 * @param daysQueryRequest	
	 * @param interval			间隔(跨度) --每次跨越多少
	 * @param type				1：天，0：小时
	 * @param multiply			跨多少刻度    --从开始到这次，需要跨越多少次
	 * @param flag			   	终止时间节点是否需要处理
	 * @return
	 */
	private void calculateEachQueryRequest(DaysQueryRequest daysQueryRequest,BigDecimal interval,int type,int multiply,boolean flag) {
		Date queryStartTime = daysQueryRequest.getOriginalQueryStartTime();
		Calendar calendarStart = Calendar.getInstance(TimeZone.getTimeZone("GMT-8"));
		calendarStart.setTime(queryStartTime);
		
		Date queryEndTime = daysQueryRequest.getOriginalQueryEndTime();
		Calendar calendarEnd = Calendar.getInstance(TimeZone.getTimeZone("GMT-8"));
		calendarEnd.setTime(queryStartTime);
		
		BigDecimal dayIntervalTotal = interval.multiply(new BigDecimal(""+multiply));
		BigDecimal newNumber = dayIntervalTotal.setScale(0, BigDecimal.ROUND_UP);
		
		if(type==0) {//小时为单元
			calendarEnd.add(Calendar.HOUR_OF_DAY, newNumber.intValue());
			queryEndTime = calendarEnd.getTime();
			
			calendarStart.add(Calendar.HOUR_OF_DAY, newNumber.intValue());
			queryStartTime = calendarStart.getTime();
		}else if(type==1){//天为单元
			if(interval.intValue()==1) {
				calendarStart.add(Calendar.DAY_OF_YEAR, newNumber.intValue());
				queryStartTime = calendarStart.getTime();
				
				calendarEnd.add(Calendar.DAY_OF_YEAR, newNumber.intValue());
				queryEndTime = calendarEnd.getTime();
			}else if(interval.intValue()==6) {
				calendarStart.add(Calendar.DAY_OF_YEAR, multiply);
				calendarEnd.add(Calendar.DAY_OF_YEAR, multiply);
				
				calendarStart.add(Calendar.DAY_OF_YEAR, newNumber.intValue());
				queryStartTime = calendarStart.getTime();
				
				calendarEnd.add(Calendar.DAY_OF_YEAR, newNumber.intValue()+6);
				queryEndTime = calendarEnd.getTime();
				
			}else if(interval.intValue()==29) {
				
				calendarStart.add(Calendar.DAY_OF_YEAR, multiply);
				calendarEnd.add(Calendar.DAY_OF_YEAR, multiply);
				
				calendarStart.add(Calendar.DAY_OF_YEAR, newNumber.intValue());
				queryStartTime = calendarStart.getTime();
				
				calendarEnd.add(Calendar.DAY_OF_YEAR, newNumber.intValue()+30);
				queryEndTime = calendarEnd.getTime();
			}
			//处理最后一个时段的截止日期越界的问题
			if(flag==true) {
				queryEndTime = daysQueryRequest.getOriginalQueryEndTime();
			}
		}
		daysQueryRequest.setQueryStartTime(queryStartTime);
		daysQueryRequest.setQueryEndTime(queryEndTime);
	}
	/**
	 * 
	 * @Method:caculateTimeDetailEachQueryRequest
	 * @Description:每天一段时间
	 * @Time 2018年3月7日 下午4:09:45
	 * @author: Tom
	 * @param daysQueryRequest	
	 * @param i 				增加的天数
	 */
	public void caculateTimeDetailEachQueryRequest(DaysQueryRequest daysQueryRequest,int i) {
		//每天
		Date queryStartTime = daysQueryRequest.getOriginalQueryStartTime();
		Calendar calendarStart = Calendar.getInstance(TimeZone.getTimeZone("GMT-8"));
		calendarStart.setTime(queryStartTime);
		//获取截止时刻（小时）
		Date queryEndTime = daysQueryRequest.getOriginalQueryEndTime();
		String timeEndLastStr = DateFormatUtil.formatDate(daysQueryRequest.getOriginalQueryEndTime(),DateFormatUtil.DATETIME_PATTERN).substring(11);
		String timeEndHeadStr = DateFormatUtil.formatDate(queryStartTime);
		Date timeEnd = DateFormatUtil.parseDatePattern(timeEndHeadStr+" "+timeEndLastStr,DateFormatUtil.DATETIME_PATTERN);
		Calendar calendarEnd = Calendar.getInstance(TimeZone.getTimeZone("GMT-8"));
		calendarEnd.setTime(timeEnd);
		//
		calendarStart.add(Calendar.DAY_OF_YEAR, i);
		queryStartTime = calendarStart.getTime();
		
		calendarEnd.add(Calendar.DAY_OF_YEAR, i);
		queryEndTime = calendarEnd.getTime();
		
		daysQueryRequest.setQueryStartTime(queryStartTime);
		daysQueryRequest.setQueryEndTime(queryEndTime);
		
	}
	private UserOperationCurveResponse handlerUserEachStatistics(DaysQueryRequest daysQueryRequest) {
		List<OperationResponse> operationResponses = new ArrayList<OperationResponse>();
		// TODO时间分组不成立
		UserStatistics userStatistics = userInfoDao.daysUser(daysQueryRequest);
		OperationResponse dayUserOperation = new OperationResponse();
		dayUserOperation.setKey("注册用户");
		dayUserOperation.setValue(userStatistics.getAddUser());
		operationResponses.add(dayUserOperation);
		//今日新增有效押金人员
		CapitalStatistics dyaDepositUser = userChargeLogDao.daysAvailableDepositUser(daysQueryRequest);//daysEachDepositUser
		OperationResponse dayDepositUserOperation = new OperationResponse();
		dayDepositUserOperation.setKey("有效押金用户");
		dayDepositUserOperation.setValue(dyaDepositUser.getAvailableDepositUser());
		operationResponses.add(dayDepositUserOperation);
		
		CapitalStatistics daysCashUser = userChargeLogDao.daysCashUser(daysQueryRequest);
		OperationResponse dayCashUserOperation = new OperationResponse();
		dayCashUserOperation.setKey("充值用户");
		dayCashUserOperation.setValue(daysCashUser.getCashUser());
		operationResponses.add(dayCashUserOperation);
		
		VipStatistics vipMonthUserStatistics = vipMemberDao.daysVipMonth(daysQueryRequest);
		OperationResponse vipMonthUserOperation = new OperationResponse();
		vipMonthUserOperation.setKey("月卡会员");
		vipMonthUserOperation.setValue(vipMonthUserStatistics.getVipMonthUsers());
		operationResponses.add(vipMonthUserOperation);
		
		VipStatistics vipYearUserStatistics = vipMemberDao.daysVipYear(daysQueryRequest);
		OperationResponse vipYearUserOperation = new OperationResponse();
		vipYearUserOperation.setKey("年卡会员");
		vipYearUserOperation.setValue(vipYearUserStatistics.getVipYearUsers());
		operationResponses.add(vipYearUserOperation);
		
		CapitalStatistics dayRefundDepositUser = userChargeLogDao.daysRefundDepositUser(daysQueryRequest);//daysEachRefundDepositUser
		OperationResponse dayRefundDepositUserOperation = new OperationResponse();
		dayRefundDepositUserOperation.setKey("退押金用户");
		dayRefundDepositUserOperation.setValue(dayRefundDepositUser.getRefundDepositUser());
		operationResponses.add(dayRefundDepositUserOperation);
		
		BorrowStatistics daysBorrowedUsers = orderTransDao.daysBorrowUsers(daysQueryRequest);
		OperationResponse dayBorrowedUserOperation = new OperationResponse();
		dayBorrowedUserOperation.setKey("借阅用户(活跃用户)");
		dayBorrowedUserOperation.setValue(daysBorrowedUsers.getBorrowUsers());
		operationResponses.add(dayBorrowedUserOperation);
		
		UserOperationCurveResponse curveResponse = new UserOperationCurveResponse();
		curveResponse.setDateStr(DateFormatUtil.formateDateToString(daysQueryRequest.getQueryStartTime(), DateFormatUtil.DATE_PATTERN_LEAN));
		curveResponse.setOperationResponses(operationResponses);
		
		return curveResponse;
	}
	
	@Override
	public List<UserOperationCurveResponse> daysUserEachStatistics(DaysQueryRequest daysQueryRequest) {
		daysQueryRequest.setQueryStartTime(daysQueryRequest.getOriginalQueryStartTime());
		daysQueryRequest.setQueryEndTime(daysQueryRequest.getOriginalQueryEndTime());
		List<UserOperationCurveResponse> list = new ArrayList<>();
		this.initQueryRequest(daysQueryRequest);
		Date queryEndTime = daysQueryRequest.getQueryEndTime();
		Date queryStartTime = daysQueryRequest.getQueryStartTime();
		if(queryStartTime==null) {
			return null;
		}
		long diff = queryEndTime.getTime() - queryStartTime.getTime();
		long days = diff / (1000 * 60 * 60 * 24)+1;  
		if(days<=1) {//直接24小时
			daysQueryRequest.setGroupCondition("1");
			String dateStr = DateFormatUtil.formatDate(daysQueryRequest.getQueryStartTime());
			Date starTime = DateFormatUtil.parseDate(dateStr);
			
			daysQueryRequest.setOriginalQueryStartTime(starTime);
			daysQueryRequest.setQueryStartTime(starTime);
			
			String endDateStr = dateStr+" 23:59:59";
			Date endTime = DateFormatUtil.parseDatePattern(endDateStr, DateFormatUtil.DATETIME_PATTERN);
			daysQueryRequest.setOriginalQueryEndTime(endTime);
			daysQueryRequest.setQueryEndTime(endTime);
			
			//List<StatisticsEntity> statisticsEntitys = statisticsDao.selectDaysStatistics(daysQueryRequest);
			for(int i=0;i<23;i++) {
				this.calculateEachQueryRequest(daysQueryRequest, new BigDecimal("1"), 0,i,false);
				UserOperationCurveResponse userOperationCurveResponse = this.handlerUserEachStatistics(daysQueryRequest);
				list.add(userOperationCurveResponse);
			}
		}else if( days>1 && days<=30) {//每天
			daysQueryRequest.setGroupCondition("0");
			//List<StatisticsEntity> statisticsEntitys = statisticsDao.selectDaysStatistics(daysQueryRequest);
			for(int i=0;i<days;i++) {
				this.calculateEachQueryRequest(daysQueryRequest, new BigDecimal("1"), 1,i,false);
				UserOperationCurveResponse userOperationCurveResponse = this.handlerUserEachStatistics(daysQueryRequest);
				list.add(userOperationCurveResponse);
			}
		}else if(days>30 && days<=182) {//每周
			daysQueryRequest.setGroupCondition("0");
			int times = (int) (days/7)+1;
			//List<StatisticsEntity> statisticsEntitys = statisticsDao.selectDaysStatistics(daysQueryRequest);
			for(int i=0;i<times;i++) {
				if(i==times-1) {
					this.calculateEachQueryRequest(daysQueryRequest, new BigDecimal("6"), 1,i,true);
				}else {
					this.calculateEachQueryRequest(daysQueryRequest, new BigDecimal("6"), 1,i,false);
				}
				UserOperationCurveResponse userOperationCurveResponse = this.handlerUserEachStatistics( daysQueryRequest);
				list.add(userOperationCurveResponse);
			}
		}else if(days>182) {//每月
			daysQueryRequest.setGroupCondition("0");
			int times = (int) (days/30)+1;
			//List<StatisticsEntity> statisticsEntitys = statisticsDao.selectDaysStatistics(daysQueryRequest);
			for(int i=0;i<times;i++) {
				if(i==times-1) {
					this.calculateEachQueryRequest(daysQueryRequest, new BigDecimal("29"), 1,i,true);
				}else {
					this.calculateEachQueryRequest(daysQueryRequest, new BigDecimal("29"), 1,i,false);
				}
				UserOperationCurveResponse userOperationCurveResponse = this.handlerUserEachStatistics( daysQueryRequest);
				list.add(userOperationCurveResponse);
			}
		}
		return list;
	}
	
	@Override
	public List<OperationResponse> daysCapitalTotalStatistics(DaysQueryRequest daysQueryRequest) {
		//判断时间是否为天；
		long diff = daysQueryRequest.getQueryEndTime().getTime() - daysQueryRequest.getQueryStartTime().getTime();
		//判断是否真的小于1天
		String dateStartStr = DateFormatUtil.formatDate(daysQueryRequest.getQueryStartTime());
		String dateEndStr = DateFormatUtil.formatDate(daysQueryRequest.getQueryEndTime());
		this.initQueryRequest(daysQueryRequest);
		long days = diff / (1000 * 60 * 60 * 24)+1;  
		if(days<1) {
			if(dateStartStr.equals(dateEndStr)) {
				days = 1;
			}else {
				days = 2;
			}
		}
		daysQueryRequest.setGroupCondition("1");
		List<OperationResponse> operationResponses = new ArrayList<OperationResponse>();
		BigDecimal daysAvailableDepisitTotalBig = new BigDecimal("0");
		BigDecimal daysAvailableCashTotalBig = new BigDecimal("0");
		BigDecimal daysVipMonthCashTotalBig = new BigDecimal("0");
		BigDecimal daysAvailableVipMonthCashTotalBig = new BigDecimal("0");
		BigDecimal daysVipYearCashTotalBig = new BigDecimal("0");
		BigDecimal daysAvailableVipYearCashTotalBig = new BigDecimal("0");
		BigDecimal daysRefundDepositTotalBig = new BigDecimal("0");
		BigDecimal daysActiveCashTotalBig = new BigDecimal("0");
		BigDecimal daysTotalCashTotalBig = new BigDecimal("0");
		for(int i=0;i<days;i++) {
			this.caculateTimeDetailEachQueryRequest(daysQueryRequest, i);
			//有效押金
			CapitalStatistics daysAvailableDeposit = userChargeLogDao.daysAvailableDeposit(daysQueryRequest);//daysTotalDepositUser
			daysAvailableDepisitTotalBig = daysAvailableDepisitTotalBig.add(new BigDecimal(daysAvailableDeposit.getAvailableDeposit()));
			//充值余额(实际)
			CapitalStatistics daysCash = userChargeLogDao.daysCash(daysQueryRequest);
			daysAvailableCashTotalBig = daysAvailableCashTotalBig.add(new BigDecimal(daysCash.getCash()));
			//充值余额(活动赠送)
			CapitalStatistics daysActiveCashStatistics =  accountCashLogDao.daysActiveCash(daysQueryRequest);
			daysActiveCashTotalBig = daysActiveCashTotalBig.add(new BigDecimal(daysActiveCashStatistics.getActiveCash()));
			//充值余额(总计)
			daysTotalCashTotalBig = daysTotalCashTotalBig.add(daysAvailableCashTotalBig).add(daysActiveCashTotalBig);
			//年卡充值金额(有效)
			VipStatistics vipAvailableCashYearStatistics = vipMemberLogDao.daysVipAvailableCashYear(daysQueryRequest);
			daysAvailableVipYearCashTotalBig = daysAvailableVipYearCashTotalBig.add(new BigDecimal(vipAvailableCashYearStatistics.getVipAvailableYearCash()));
			//年卡充值金额(总计)
			VipStatistics vipYearStatistics = vipMemberLogDao.daysVipCashYear(daysQueryRequest);
			daysVipYearCashTotalBig = daysVipYearCashTotalBig.add(new BigDecimal(vipYearStatistics.getVipYearCash()));
			//月卡充值金额(有效)
			VipStatistics vipAvailableMonthStatistics = vipMemberLogDao.daysVipAvailableCashMonth(daysQueryRequest);
			daysAvailableVipMonthCashTotalBig = daysAvailableVipMonthCashTotalBig.add(new BigDecimal(vipAvailableMonthStatistics.getVipAvailableMonthCash()));
			//月卡充值金额(总计)
			VipStatistics vipMonthStatistics = vipMemberLogDao.daysVipCashMonth(daysQueryRequest);
			daysVipMonthCashTotalBig = daysVipMonthCashTotalBig.add(new BigDecimal(vipMonthStatistics.getVipMonthCash()));
			//退押金
			CapitalStatistics dayRefundDeposit = userChargeLogDao.daysRefundDeposit(daysQueryRequest);//daysTotalRefundDepositUser
			daysRefundDepositTotalBig = daysRefundDepositTotalBig.add(new BigDecimal(dayRefundDeposit.getRefundDeposit()));
		}
		OperationResponse dayDepositUserOperation = new OperationResponse();
		dayDepositUserOperation.setKey("缴纳押金");
		dayDepositUserOperation.setValue(daysAvailableDepisitTotalBig.toString());
		operationResponses.add(dayDepositUserOperation);
		
		//充值余额(实际)
		OperationResponse dayCashAmountOperation = new OperationResponse();
		dayCashAmountOperation.setKey("充值余额(有效)");
		dayCashAmountOperation.setValue(daysAvailableCashTotalBig.toString());
		operationResponses.add(dayCashAmountOperation);
		//充值余额(活动赠送)
		OperationResponse dayActiveCashAmountOperation = new OperationResponse();
		dayActiveCashAmountOperation.setKey("充值余额(活动赠送)");
		dayActiveCashAmountOperation.setValue(daysActiveCashTotalBig.toString());
		operationResponses.add(dayActiveCashAmountOperation);
		//年卡充值金额(有效)
		OperationResponse daysAvailableTotalVipCashYearOperation = new OperationResponse();
		daysAvailableTotalVipCashYearOperation.setKey("年卡充值金额(有效)");
		daysAvailableTotalVipCashYearOperation.setValue(daysAvailableVipYearCashTotalBig.toString());
		operationResponses.add(daysAvailableTotalVipCashYearOperation);
		//年卡充值金额(活动)
		OperationResponse daysActiveTotalVipCashYearOperation = new OperationResponse();
		daysActiveTotalVipCashYearOperation.setKey("年卡充值金额(活动赠送)");
		daysActiveTotalVipCashYearOperation.setValue(daysVipYearCashTotalBig.subtract(daysAvailableVipYearCashTotalBig).toString());
		operationResponses.add(daysActiveTotalVipCashYearOperation);
		//年卡充值金额
		OperationResponse daysTotalVipCashYearOperation = new OperationResponse();
		daysTotalVipCashYearOperation.setKey("年卡充值金额");
		daysTotalVipCashYearOperation.setValue(daysVipYearCashTotalBig.toString());
		operationResponses.add(daysTotalVipCashYearOperation);
		//月卡充值金额(有效)
		OperationResponse daysAvailableTotalVipCashMonthOperation = new OperationResponse();
		daysAvailableTotalVipCashMonthOperation.setKey("月卡充值金额(有效)");
		daysAvailableTotalVipCashMonthOperation.setValue(daysAvailableVipMonthCashTotalBig.toString());
		operationResponses.add(daysAvailableTotalVipCashMonthOperation);
		//月卡充值金额(活动赠送)
		OperationResponse daysActiveTotalVipCashMonthOperation = new OperationResponse();
		daysActiveTotalVipCashMonthOperation.setKey("月卡充值金额(活动赠送)");
		daysActiveTotalVipCashMonthOperation.setValue(daysVipMonthCashTotalBig.subtract(daysAvailableVipMonthCashTotalBig).toString());
		operationResponses.add(daysActiveTotalVipCashMonthOperation);
		//月卡充值金额(活动赠送)
		OperationResponse daysTotalVipCashMonthOperation = new OperationResponse();
		daysTotalVipCashMonthOperation.setKey("月卡充值金额(总计)");
		daysTotalVipCashMonthOperation.setValue(daysVipMonthCashTotalBig.toString());
		operationResponses.add(daysTotalVipCashMonthOperation);
		//活动支出
		OperationResponse daysTotalActiveCashOperation = new OperationResponse();
		daysTotalActiveCashOperation.setKey("活动支出");
		daysTotalActiveCashOperation.setValue(daysActiveCashTotalBig.toString());
		operationResponses.add(daysTotalActiveCashOperation);
		//已退押金
		OperationResponse daysRefundDepositOperation = new OperationResponse();
		daysRefundDepositOperation.setKey("已退押金");
		daysRefundDepositOperation.setValue(daysRefundDepositTotalBig.toString());
		operationResponses.add(daysRefundDepositOperation);
		
		return operationResponses;
	}
	@Override
	public List<OperationResponse> daysBookShelfTotalStatistics(DaysQueryRequest daysQueryRequest) {
		
		//判断时间是否为天；
		long diff = daysQueryRequest.getQueryEndTime().getTime() - daysQueryRequest.getQueryStartTime().getTime();
		//判断是否真的小于1天
		String dateStartStr = DateFormatUtil.formatDate(daysQueryRequest.getQueryStartTime());
		String dateEndStr = DateFormatUtil.formatDate(daysQueryRequest.getQueryEndTime());
		this.initQueryRequest(daysQueryRequest);
		long days = diff / (1000 * 60 * 60 * 24)+1;  
		if(days<1) {
			if(dateStartStr.equals(dateEndStr)) {
				days = 1;
			}else {
				days = 2;
			}
		}
		daysQueryRequest.setGroupCondition("1");
		List<OperationResponse> operationResponses = new ArrayList<OperationResponse>();
		BigDecimal daysUserTotalBig = new BigDecimal("0");
		BigDecimal daysRefundDepositUserTotalBig  = new BigDecimal("0");
		BigDecimal daysAvailableDepisitTotalBig = new BigDecimal("0");
		BigDecimal daysAvailableDepisitUserTotalBig = new BigDecimal("0");
		BigDecimal daysAvailableCashTotalBig = new BigDecimal("0");
		BigDecimal daysAvailableVipYearUserTotalBig = new BigDecimal("0");
		BigDecimal daysAvailableVipMonthUserTotalBig = new BigDecimal("0");
		BigDecimal daysBorrowBooksTotalBig = new BigDecimal("0");
		for(int i=0;i<days;i++) {
			this.caculateTimeDetailEachQueryRequest(daysQueryRequest, i);
			//用户
			UserStatistics daysUserStatistics = userInfoDao.daysUser(daysQueryRequest);
			daysUserTotalBig = daysUserTotalBig.add(new BigDecimal(daysUserStatistics.getAddUser()));
			//有效押金用户
			CapitalStatistics daysAvailableDepositUser = userChargeLogDao.daysAvailableDepositUser(daysQueryRequest);
			daysAvailableDepisitUserTotalBig = daysAvailableDepisitUserTotalBig.add(new BigDecimal(daysAvailableDepositUser.getAvailableDepositUser()));
			//有效押金金额
			CapitalStatistics daysAvailableDeposit = userChargeLogDao.daysAvailableDeposit(daysQueryRequest);
			daysAvailableDepisitTotalBig = daysAvailableDepisitTotalBig.add(new BigDecimal(daysAvailableDeposit.getAvailableDeposit()));
			//充值余额(有效)
			CapitalStatistics daysCash = userChargeLogDao.daysCash(daysQueryRequest);
			daysAvailableCashTotalBig = daysAvailableCashTotalBig.add(new BigDecimal(daysCash.getCash()));
			//退押金用户数
			CapitalStatistics daysRefundDepositUser = userChargeLogDao.daysRefundDepositUser(daysQueryRequest);
			daysRefundDepositUserTotalBig = daysRefundDepositUserTotalBig.add(new BigDecimal(daysRefundDepositUser.getRefundDepositUser()));
			//年卡会员(有效)
			VipStatistics vipAvailableYearsUser = vipMemberDao.daysAvailableVipYear(daysQueryRequest);
			daysAvailableVipYearUserTotalBig = daysAvailableVipYearUserTotalBig.add( new BigDecimal(vipAvailableYearsUser.getVipAvailableYearUsers()) );
			//月卡会员(有效)
			VipStatistics vipAvailableMonthUser = vipMemberDao.daysAvailableVipMonth(daysQueryRequest);
			daysAvailableVipMonthUserTotalBig = daysAvailableVipMonthUserTotalBig.add( new BigDecimal(vipAvailableMonthUser.getVipAvailableMonthUsers()) );
			//借阅书籍
			BorrowStatistics borrowStatistics = orderTransDao.daysBorrowBooks(daysQueryRequest);
			daysBorrowBooksTotalBig = daysBorrowBooksTotalBig.add( new BigDecimal(borrowStatistics.getBorrowBooks()) );
		}
		//注册用户
		OperationResponse daysUserOperation = new OperationResponse();
		daysUserOperation.setKey("注册用户");
		daysUserOperation.setValue(daysUserTotalBig.toString());
		operationResponses.add(daysUserOperation);
		//缴纳押金
		OperationResponse dayDepositUserOperation = new OperationResponse();
		dayDepositUserOperation.setKey("缴纳押金用户");
		dayDepositUserOperation.setValue(daysAvailableDepisitUserTotalBig.toString());
		operationResponses.add(dayDepositUserOperation);
		//有效押金金额
		OperationResponse dayDepositOperation = new OperationResponse();
		dayDepositOperation.setKey("有效押金金额");
		dayDepositOperation.setValue(daysAvailableDepisitTotalBig.toString());
		operationResponses.add(dayDepositOperation);
		//充值余额(实际)
		OperationResponse dayCashAmountOperation = new OperationResponse();
		dayCashAmountOperation.setKey("充值余额(有效)");
		dayCashAmountOperation.setValue(daysAvailableCashTotalBig.toString());
		operationResponses.add(dayCashAmountOperation);
		//充值余额(实际)
		OperationResponse dayRefundDepositUsersOperation = new OperationResponse();
		dayRefundDepositUsersOperation.setKey("退押金用户数");
		dayRefundDepositUsersOperation.setValue(daysRefundDepositUserTotalBig.toString());
		operationResponses.add(dayRefundDepositUsersOperation);
		//年卡会员
		OperationResponse daysVipYearUserOperation = new OperationResponse();
		daysVipYearUserOperation.setKey("年卡会员(有效)");
		daysVipYearUserOperation.setValue(daysAvailableVipYearUserTotalBig.toString());
		operationResponses.add(daysVipYearUserOperation);
		//月卡会员
		OperationResponse daysVipMonthUserOperation = new OperationResponse();
		daysVipMonthUserOperation.setKey("月卡会员(有效)");
		daysVipMonthUserOperation.setValue(daysAvailableVipMonthUserTotalBig.toString());
		operationResponses.add(daysVipMonthUserOperation);
		//借阅书籍
		OperationResponse daysBorrowBooksOperation = new OperationResponse();
		daysBorrowBooksOperation.setKey("出借书籍数");
		daysBorrowBooksOperation.setValue(daysBorrowBooksTotalBig.toString());
		operationResponses.add(daysBorrowBooksOperation);
		
		return operationResponses;
	}
	/**
	 * 
	 * @Method:handlerCapitalEachStatistics
	 * @Description:用户资金曲线图
	 * @Time 2018年2月28日 下午1:46:10
	 * @author: Tom
	 * @param statisticsEntity
	 * @param daysQueryRequest
	 * @return
	 */
	private UserOperationCurveResponse handlerCapitalEachStatistics(DaysQueryRequest daysQueryRequest) {
		List<OperationResponse> operationResponses = new ArrayList<OperationResponse>();
		//今日新增有效押金
		CapitalStatistics dyaDeposit = userChargeLogDao.daysAvailableDeposit(daysQueryRequest);//daysEachDeposit(daysQueryRequest);
		OperationResponse dayDepositOperation = new OperationResponse();
		dayDepositOperation.setKey("缴纳押金");
		dayDepositOperation.setValue(dyaDeposit.getAvailableDeposit());
		operationResponses.add(dayDepositOperation);
		//充值余额（有效）
		CapitalStatistics daysCashStatistics = userChargeLogDao.daysCash(daysQueryRequest);
		OperationResponse dayCashOperation = new OperationResponse();
		dayCashOperation.setKey("充值余额(有效)");
		dayCashOperation.setValue(daysCashStatistics.getCash());
		operationResponses.add(dayCashOperation);
		//充值余额(活动赠送)
		CapitalStatistics daysActiveCashStatistics = accountCashLogDao.daysActiveCash(daysQueryRequest);
		OperationResponse dayActiveCashOperation = new OperationResponse();
		dayActiveCashOperation.setKey("充值余额(活动赠送)");
		dayActiveCashOperation.setValue(daysActiveCashStatistics.getActiveCash());
		operationResponses.add(dayActiveCashOperation);
		//充值余额(总计)
		OperationResponse daysTotalCashOperation = new OperationResponse();
		daysTotalCashOperation.setKey("充值余额(总计)");
		daysTotalCashOperation.setValue(new BigDecimal(daysCashStatistics.getCash()).add(new BigDecimal(daysActiveCashStatistics.getActiveCash())).toString());
		operationResponses.add(daysTotalCashOperation);
		//年卡充值金额(有效)
		VipStatistics daysAvailableVipCashYear = vipMemberLogDao.daysVipAvailableCashYear(daysQueryRequest);//daysEachVipCashYear(daysQueryRequest);
		OperationResponse dayAvailableVipCashYearOperation = new OperationResponse();
		dayAvailableVipCashYearOperation.setKey("年卡充值金额(有效)");
		dayAvailableVipCashYearOperation.setValue(daysAvailableVipCashYear.getVipAvailableYearCash());
		operationResponses.add(dayAvailableVipCashYearOperation);
		//年卡充值金额(活动赠送)
		VipStatistics dayTotalVipCashYear = vipMemberLogDao.daysVipCashYear(daysQueryRequest);//daysEachVipCashMonth(daysQueryRequest);
		OperationResponse dayActiveVipCashYearOperation = new OperationResponse();
		dayActiveVipCashYearOperation.setKey("年卡充值金额(活动赠送)");
		dayActiveVipCashYearOperation.setValue(new BigDecimal(dayTotalVipCashYear.getVipYearCash()).subtract(new BigDecimal(daysAvailableVipCashYear.getVipAvailableYearCash())).toString());
		operationResponses.add(dayActiveVipCashYearOperation);
		//年卡充值金额(总计)
		OperationResponse dayTotalVipCashYearOperation = new OperationResponse();
		dayTotalVipCashYearOperation.setKey("年卡充值金额(总计)");
		dayTotalVipCashYearOperation.setValue(dayTotalVipCashYear.getVipYearCash());
		operationResponses.add(dayTotalVipCashYearOperation);
		//年卡充值金额(有效)
		VipStatistics daysAvailableVipCashMonth = vipMemberLogDao.daysVipAvailableCashMonth(daysQueryRequest);//daysEachVipCashYear(daysQueryRequest);
		OperationResponse dayAvailableVipCashMonthOperation = new OperationResponse();
		dayAvailableVipCashMonthOperation.setKey("月卡充值金额(有效)");
		dayAvailableVipCashMonthOperation.setValue(daysAvailableVipCashMonth.getVipAvailableMonthCash());
		operationResponses.add(dayAvailableVipCashMonthOperation);
		//年卡充值金额(活动赠送)
		VipStatistics dayTotalVipCashMonth = vipMemberLogDao.daysVipCashMonth(daysQueryRequest);//daysEachVipCashMonth(daysQueryRequest);
		OperationResponse dayActiveVipCashMonthOperation = new OperationResponse();
		dayActiveVipCashMonthOperation.setKey("月卡充值金额(活动赠送)");
		dayActiveVipCashMonthOperation.setValue(new BigDecimal(dayTotalVipCashMonth.getVipMonthCash()).subtract(new BigDecimal(daysAvailableVipCashMonth.getVipAvailableMonthCash())).toString());
		operationResponses.add(dayActiveVipCashMonthOperation);
		//年卡充值金额(总计)
		OperationResponse dayTotalVipCashMonthOperation = new OperationResponse();
		dayTotalVipCashMonthOperation.setKey("月卡充值金额(总计)");
		dayTotalVipCashMonthOperation.setValue(dayTotalVipCashMonth.getVipMonthCash());
		operationResponses.add(dayTotalVipCashMonthOperation);
		//活动支出
		CapitalStatistics dayEachActiveCash = accountCashLogDao.daysActiveCash(daysQueryRequest);
		OperationResponse dayEachActiveCashOperation = new OperationResponse();
		dayEachActiveCashOperation.setKey("活动支出");
		dayEachActiveCashOperation.setValue(dayEachActiveCash.getActiveCash());
		operationResponses.add(dayEachActiveCashOperation);
		//已退押金
		CapitalStatistics dayRefundDeposit = userChargeLogDao.daysRefundDeposit(daysQueryRequest);//daysEachRefundDeposit(daysQueryRequest);
		OperationResponse dayRefundDepositOperation = new OperationResponse();
		dayRefundDepositOperation.setKey("已退押金");
		dayRefundDepositOperation.setValue(dayRefundDeposit.getRefundDeposit());
		operationResponses.add(dayRefundDepositOperation);
		
		/*BigDecimal profit = new BigDecimal("0");
		profit = profit.add(new BigDecimal(dyaDeposit.getAvailableDeposit()));
		profit = profit.add(statisticsEntity.getCashAmount()==null?new BigDecimal("0"):statisticsEntity.getCashAmount());
		profit = profit.add(new BigDecimal(dayEachVipCashYear.getVipYearCash()));
		profit = profit.add(new BigDecimal(dayEachVipCashMonth.getVipMonthCash()));
		profit = profit.subtract(new BigDecimal(dayEachActiveCash));
		profit = profit.subtract(new BigDecimal(dayRefundDeposit.getRefundDeposit()));
		OperationResponse daysTotalProfitOperation = new OperationResponse();
		daysTotalProfitOperation.setKey("利润");
		daysTotalProfitOperation.setValue(profit.toString());
		operationResponses.add(daysTotalProfitOperation);*/
		
		UserOperationCurveResponse curveResponse = new UserOperationCurveResponse();
		curveResponse.setDateStr(DateFormatUtil.formateDateToString(daysQueryRequest.getQueryStartTime(), DateFormatUtil.DATE_PATTERN_LEAN));
		curveResponse.setOperationResponses(operationResponses);
		return curveResponse;
	}
	@Override
	public List<UserOperationCurveResponse> daysCapitalEachStatistics(DaysQueryRequest daysQueryRequest) {
		daysQueryRequest.setQueryStartTime(daysQueryRequest.getOriginalQueryStartTime());
		daysQueryRequest.setQueryEndTime(daysQueryRequest.getOriginalQueryEndTime());
		List<UserOperationCurveResponse> list = new ArrayList<>();
		this.initQueryRequest(daysQueryRequest);
		Date queryEndTime = daysQueryRequest.getQueryEndTime();
		Date queryStartTime = daysQueryRequest.getQueryStartTime();
		if(queryStartTime==null) {
			return null;
		}
		long diff = queryEndTime.getTime() - queryStartTime.getTime();
		long days = diff / (1000 * 60 * 60 * 24)+1;  
		if(days<=1) {//直接24小时
			daysQueryRequest.setGroupCondition("1");
			String dateStr = DateFormatUtil.formatDate(daysQueryRequest.getQueryStartTime());
			Date starTime = DateFormatUtil.parseDate(dateStr);
			
			daysQueryRequest.setOriginalQueryStartTime(starTime);
			daysQueryRequest.setQueryStartTime(starTime);
			
			String endDateStr = dateStr+" 23:59:59";
			Date endTime = DateFormatUtil.parseDatePattern(endDateStr, DateFormatUtil.DATETIME_PATTERN);
			daysQueryRequest.setOriginalQueryEndTime(endTime);
			daysQueryRequest.setQueryEndTime(endTime);
			
			//List<StatisticsEntity> statisticsEntitys = statisticsDao.selectDaysStatistics(daysQueryRequest);
			for(int i=0;i<23;i++) {
				this.calculateEachQueryRequest(daysQueryRequest, new BigDecimal("1"), 0,i,false);
				UserOperationCurveResponse userOperationCurveResponse = this.handlerCapitalEachStatistics(daysQueryRequest);
				list.add(userOperationCurveResponse);
			}
		}else if( days>1 && days<=30) {//每天
			daysQueryRequest.setGroupCondition("0");
			//List<StatisticsEntity> statisticsEntitys = statisticsDao.selectDaysStatistics(daysQueryRequest);
			for(int i=0;i<days;i++) {
				this.calculateEachQueryRequest(daysQueryRequest, new BigDecimal("1"), 1,i,false);
				UserOperationCurveResponse userOperationCurveResponse = this.handlerCapitalEachStatistics(daysQueryRequest);
				list.add(userOperationCurveResponse);
			}
		}else if(days>30 && days<=182) {//每周
			daysQueryRequest.setGroupCondition("0");
			int times = (int) (days/7)+1;
			//List<StatisticsEntity> statisticsEntitys = statisticsDao.selectDaysStatistics(daysQueryRequest);
			for(int i=0;i<times;i++) {
				if(i==times-1) {
					this.calculateEachQueryRequest(daysQueryRequest, new BigDecimal("6"), 1,i,true);
				}else {
					this.calculateEachQueryRequest(daysQueryRequest, new BigDecimal("6"), 1,i,false);
				}
				UserOperationCurveResponse userOperationCurveResponse = this.handlerCapitalEachStatistics(daysQueryRequest);
				list.add(userOperationCurveResponse);
			}
		}else if(days>182) {//每月
			daysQueryRequest.setGroupCondition("0");
			int times = (int) (days/30)+1;
			//List<StatisticsEntity> statisticsEntitys = statisticsDao.selectDaysStatistics(daysQueryRequest);
			for(int i=0;i<times;i++) {
				if(i==times-1) {
					this.calculateEachQueryRequest(daysQueryRequest, new BigDecimal("29"), 1,i,true);
				}else {
					this.calculateEachQueryRequest(daysQueryRequest, new BigDecimal("29"), 1,i,false);
				}
				UserOperationCurveResponse userOperationCurveResponse = this.handlerCapitalEachStatistics(daysQueryRequest);
				list.add(userOperationCurveResponse);
			}
		}
		return list;
	}
	/**
	 * 
	 * @Method:handlerBookShelfEachStatistics
	 * @Description:书柜数据统计
	 * @Time 2018年2月28日 下午2:51:35
	 * @author: Tom
	 * @param statisticsEntity
	 * @param daysQueryRequest
	 * @return
	 */
	private UserOperationCurveResponse handlerBookShelfEachStatistics(DaysQueryRequest daysQueryRequest) {
		List<OperationResponse> operationResponses = new ArrayList<OperationResponse>();
		//注册用户
		UserStatistics daysUserStatistics = userInfoDao.daysUser(daysQueryRequest);
		OperationResponse daysUserOperation = new OperationResponse();
		daysUserOperation.setKey("注册用户");
		daysUserOperation.setValue(daysUserStatistics.getAddUser());
		operationResponses.add(daysUserOperation);
		//有效押金用户
		CapitalStatistics daysAvailableDepositUser = userChargeLogDao.daysAvailableDepositUser(daysQueryRequest);
		OperationResponse dayDepositUserOperation = new OperationResponse();
		dayDepositUserOperation.setKey("缴纳押金用户");
		dayDepositUserOperation.setValue(daysAvailableDepositUser.getAvailableDepositUser());
		operationResponses.add(dayDepositUserOperation);
		//有效押金金额
		CapitalStatistics daysAvailableDeposit = userChargeLogDao.daysAvailableDeposit(daysQueryRequest);
		OperationResponse dayDepositOperation = new OperationResponse();
		dayDepositOperation.setKey("有效押金金额");
		dayDepositOperation.setValue(daysAvailableDeposit.getAvailableDeposit());
		operationResponses.add(dayDepositOperation);
		//充值余额(有效)
		CapitalStatistics daysCash = userChargeLogDao.daysCash(daysQueryRequest);
		OperationResponse dayCashAmountOperation = new OperationResponse();
		dayCashAmountOperation.setKey("充值余额(有效)");
		dayCashAmountOperation.setValue(daysCash.getCash());
		operationResponses.add(dayCashAmountOperation);
		//退押金用户数
		CapitalStatistics daysRefundDepositUser = userChargeLogDao.daysRefundDepositUser(daysQueryRequest);
		OperationResponse dayRefundDepositUsersOperation = new OperationResponse();
		dayRefundDepositUsersOperation.setKey("退押金用户数");
		dayRefundDepositUsersOperation.setValue(daysRefundDepositUser.getRefundDepositUser());
		operationResponses.add(dayRefundDepositUsersOperation);
		//年卡会员(有效)
		VipStatistics vipAvailableYearsUser = vipMemberDao.daysAvailableVipYear(daysQueryRequest);
		OperationResponse daysVipYearUserOperation = new OperationResponse();
		daysVipYearUserOperation.setKey("年卡会员(有效)");
		daysVipYearUserOperation.setValue(vipAvailableYearsUser.getVipAvailableYearUsers());
		operationResponses.add(daysVipYearUserOperation);
		//月卡会员(有效)
		VipStatistics vipAvailableMonthUser = vipMemberDao.daysAvailableVipMonth(daysQueryRequest);
		OperationResponse daysVipMonthUserOperation = new OperationResponse();
		daysVipMonthUserOperation.setKey("月卡会员(有效)");
		daysVipMonthUserOperation.setValue(vipAvailableMonthUser.getVipAvailableMonthUsers());
		operationResponses.add(daysVipMonthUserOperation);
		//借阅书籍
		BorrowStatistics borrowStatistics = orderTransDao.daysBorrowBooks(daysQueryRequest);
		OperationResponse daysBorrowBooksOperation = new OperationResponse();
		daysBorrowBooksOperation.setKey("出借书籍数");
		daysBorrowBooksOperation.setValue(borrowStatistics.getBorrowBooks());
		operationResponses.add(daysBorrowBooksOperation);
		
		UserOperationCurveResponse curveResponse = new UserOperationCurveResponse();
		curveResponse.setDateStr(DateFormatUtil.formateDateToString(daysQueryRequest.getQueryStartTime(), DateFormatUtil.DATE_PATTERN_LEAN));
		curveResponse.setOperationResponses(operationResponses);
		return curveResponse;
	}
	
	@Override
	public List<UserOperationCurveResponse> daysBookShelfEachStatistics(DaysQueryRequest daysQueryRequest) {
		daysQueryRequest.setQueryStartTime(daysQueryRequest.getOriginalQueryStartTime());
		daysQueryRequest.setQueryEndTime(daysQueryRequest.getOriginalQueryEndTime());
		List<UserOperationCurveResponse> list = new ArrayList<>();
		this.initQueryRequest(daysQueryRequest);
		Date queryEndTime = daysQueryRequest.getQueryEndTime();
		Date queryStartTime = daysQueryRequest.getQueryStartTime();
		if(queryStartTime==null) {
			return null;
		}
		long diff = queryEndTime.getTime() - queryStartTime.getTime();
		long days = diff / (1000 * 60 * 60 * 24)+1;  
		if(days<=1) {//直接24小时
			daysQueryRequest.setGroupCondition("1");
			String dateStr = DateFormatUtil.formatDate(daysQueryRequest.getQueryStartTime());
			Date starTime = DateFormatUtil.parseDate(dateStr);
			
			daysQueryRequest.setOriginalQueryStartTime(starTime);
			daysQueryRequest.setQueryStartTime(starTime);
			
			String endDateStr = dateStr+" 23:59:59";
			Date endTime = DateFormatUtil.parseDatePattern(endDateStr, DateFormatUtil.DATETIME_PATTERN);
			daysQueryRequest.setOriginalQueryEndTime(endTime);
			daysQueryRequest.setQueryEndTime(endTime);
			
			//List<StatisticsEntity> statisticsEntitys = statisticsDao.selectDaysStatistics(daysQueryRequest);
			for(int i=0;i<23;i++) {
				this.calculateEachQueryRequest(daysQueryRequest, new BigDecimal("1"), 0,i,false);
				UserOperationCurveResponse userOperationCurveResponse = this.handlerBookShelfEachStatistics(daysQueryRequest);
				list.add(userOperationCurveResponse);
			}
		}else if( days>1 && days<=30) {//每天
			daysQueryRequest.setGroupCondition("0");
			//List<StatisticsEntity> statisticsEntitys = statisticsDao.selectDaysStatistics(daysQueryRequest);
			for(int i=0;i<days;i++) {
				this.calculateEachQueryRequest(daysQueryRequest, new BigDecimal("1"), 1,i,false);
				UserOperationCurveResponse userOperationCurveResponse = this.handlerBookShelfEachStatistics(daysQueryRequest);
				list.add(userOperationCurveResponse);
			}
		}else if(days>30 && days<=182) {//每周
			daysQueryRequest.setGroupCondition("0");
			int times = (int) (days/7)+1;
			//List<StatisticsEntity> statisticsEntitys = statisticsDao.selectDaysStatistics(daysQueryRequest);
			for(int i=0;i<times;i++) {
				if(i==times-1) {
					this.calculateEachQueryRequest(daysQueryRequest, new BigDecimal("6"), 1,i,true);
				}else {
					this.calculateEachQueryRequest(daysQueryRequest, new BigDecimal("6"), 1,i,false);
				}
				UserOperationCurveResponse userOperationCurveResponse = this.handlerBookShelfEachStatistics(daysQueryRequest);
				list.add(userOperationCurveResponse);
			}
		}else if(days>182) {//每月
			daysQueryRequest.setGroupCondition("0");
			int times = (int) (days/30)+1;
			//List<StatisticsEntity> statisticsEntitys = statisticsDao.selectDaysStatistics(daysQueryRequest);
			for(int i=0;i<times;i++) {
				if(i==times-1) {
					this.calculateEachQueryRequest(daysQueryRequest, new BigDecimal("29"), 1,i,true);
				}else {
					this.calculateEachQueryRequest(daysQueryRequest, new BigDecimal("29"), 1,i,false);
				}
				UserOperationCurveResponse userOperationCurveResponse = this.handlerBookShelfEachStatistics( daysQueryRequest);
				list.add(userOperationCurveResponse);
			}
		}
		return list;
	}

	@Override
	public List<OperationResponse> bookShelfCurrentCondition(DaysQueryRequest daysQueryRequest) {
		this.initQueryRequest(daysQueryRequest);
		List<OperationResponse> list = new ArrayList<OperationResponse>();
		//查询书柜保修状态
		List<BookgridInfoEntity> bookgridInfoEntities = bookgridInfoDao.queryGridCountByShelfCode(daysQueryRequest.getBookShelfCode());
		StringBuffer buffer = new StringBuffer();
		StringBuffer gridAvailableBuffer = new StringBuffer();
 		for(BookgridInfoEntity bookgridInfoEntity:bookgridInfoEntities) {
			if(bookgridInfoEntity.getDamageReport()==1) {
				if(buffer.length()>0) {
					buffer.append(",");
				}
				buffer.append(bookgridInfoEntity.getBookgridCode().substring(10));
			}
			if(bookgridInfoEntity.getAvailable()==0) {
				if(gridAvailableBuffer.length()>0) {
					gridAvailableBuffer.append(",");
				}
				gridAvailableBuffer.append(bookgridInfoEntity.getBookgridCode().substring(10));
			}
		}
		//机柜报修状态
		OperationResponse bookShelfStatusResponse = new OperationResponse();
		bookShelfStatusResponse.setKey("机柜报修状态");
		bookShelfStatusResponse.setValue(buffer.length()>0?"保修":"正常");
		bookShelfStatusResponse.setValue(buffer.length()>0?"1":"0");
		list.add(bookShelfStatusResponse);
		//柜门报修
		OperationResponse bookShelfMaintainResponse = new OperationResponse();
		bookShelfMaintainResponse.setKey("柜门报修");
		bookShelfMaintainResponse.setValue(buffer.length()>0?buffer.toString():"无");
		bookShelfStatusResponse.setValue(buffer.length()>0?"1":"0");
		list.add(bookShelfMaintainResponse);
		//柜门灯状态
		OperationResponse bookShelfLampResponse = new OperationResponse();
		bookShelfLampResponse.setKey("柜门灯状态");
		bookShelfLampResponse.setValue("暂无数据");
		list.add(bookShelfLampResponse);
		//柜门维修
		OperationResponse bookGridAvailableResponse = new OperationResponse();
		bookGridAvailableResponse.setKey("柜门维修");
		bookGridAvailableResponse.setValue(gridAvailableBuffer.length()>0?gridAvailableBuffer.toString():"无");
		bookGridAvailableResponse.setStatus(gridAvailableBuffer.length()>0?"1":"0");
		list.add(bookGridAvailableResponse);
		//已投放书籍总计
		String countBorrowBooks = orderTransDao.countBorrowBooks(daysQueryRequest);
		OperationResponse bookShelfBorrowBooksResponse = new OperationResponse();
		bookShelfBorrowBooksResponse.setKey("已投放书籍总计");
		bookShelfBorrowBooksResponse.setValue(countBorrowBooks);
		list.add(bookShelfBorrowBooksResponse);
		//活跃用户数总计(总计押金用户)
		Date date = DateFormatUtil.parseDatePattern("2017-08-01 00:00:00", DateFormatUtil.DATETIME_PATTERN);
		daysQueryRequest.setQueryStartTime(date);
		String totalDepositUser = userChargeLogDao.daysTotalDepositUser(daysQueryRequest);
		OperationResponse bookShelfTotalDepositUserOperation = new OperationResponse();
		bookShelfTotalDepositUserOperation.setKey("有效押金用户");
		bookShelfTotalDepositUserOperation.setValue(totalDepositUser);
		list.add(bookShelfTotalDepositUserOperation);
		//出借本数
		String currentBorrowBooks = orderTransDao.curretBorrowBooks(daysQueryRequest);
		OperationResponse currentBorrowBooksOperation = new OperationResponse();
		currentBorrowBooksOperation.setKey("出借本数");
		currentBorrowBooksOperation.setValue(currentBorrowBooks);
		list.add(currentBorrowBooksOperation);
		//在柜书籍
		Integer booksCount = bookEntityDao.queryCurrentBookCount(daysQueryRequest.getBookShelfCode());
		OperationResponse bookShelfBooksCountResponse = new OperationResponse();
		bookShelfBooksCountResponse.setKey("在柜书籍");
		bookShelfBooksCountResponse.setValue(booksCount+"");
		list.add(bookShelfBooksCountResponse);
		return list;
	}

	@Override
	public List<UserOperationCurveResponse> bookShelfEntityBorrowStatistics(DaysQueryRequest daysQueryRequest) {
		//一段时间内总的借出书籍（从这个书柜里面借出的，--包括未归还的）
		daysQueryRequest.setGroupCondition("1");
		//String daysTotalBorrowBooksIsbn = orderTransDao.daysTotalBorrowBooksIsbn(daysQueryRequest);
		//一段时间内总的借出次数
		String daysTotalBorrowBooksRfid = orderTransDao.daysTotalBorrowBooks(daysQueryRequest);
		List<UserOperationCurveResponse> curveResponses = new ArrayList<UserOperationCurveResponse>();
		List<BookShelfEntityBorrow> bookShelfEntityBorrows = orderTransDao.daysEachBookBorrows(daysQueryRequest);
		for(BookShelfEntityBorrow bookShelfEntityBorrow:bookShelfEntityBorrows) {
			List<OperationResponse> operationResponses = new ArrayList<OperationResponse>();
			OperationResponse bookNameOperation = new OperationResponse();
			bookNameOperation.setKey("图书名称");
			bookNameOperation.setValue(bookShelfEntityBorrow.getBookName());
			operationResponses.add(bookNameOperation);
			
			OperationResponse borrowCountOperation = new OperationResponse();
			borrowCountOperation.setKey("出借次数");
			borrowCountOperation.setValue(bookShelfEntityBorrow.getBookBorrowCountIsbn());
			operationResponses.add(borrowCountOperation);
			
			BigDecimal bookBorrowEach = new BigDecimal(bookShelfEntityBorrow.getBookBorrowCountIsbn()==null?"0":bookShelfEntityBorrow.getBookBorrowCountIsbn());
			BigDecimal daysTotalBorrowBooksRfidBig = new BigDecimal(daysTotalBorrowBooksRfid);
			if(daysTotalBorrowBooksRfidBig.toString().equals("0")) {
				OperationResponse borrowPercentOperation = new OperationResponse();
				borrowPercentOperation.setKey("出借率");
				borrowPercentOperation.setValue("0%");
				operationResponses.add(borrowPercentOperation);
			}else {
				BigDecimal borrowPercent = (bookBorrowEach.divide(daysTotalBorrowBooksRfidBig,4,BigDecimal.ROUND_UP).multiply(new BigDecimal("100"))).setScale(2,BigDecimal.ROUND_HALF_UP);
				OperationResponse borrowPercentOperation = new OperationResponse();
				borrowPercentOperation.setKey("出借率");
				borrowPercentOperation.setValue(borrowPercent.toString()+"%");
				operationResponses.add(borrowPercentOperation);
			}
			UserOperationCurveResponse curveResponse = new UserOperationCurveResponse();
			curveResponse.setDateStr("");
			curveResponse.setOperationResponses(operationResponses);
			curveResponses.add(curveResponse);
		}
		return curveResponses;
	}
	public static void main(String[] args) {
		BigDecimal daysTotalBorrowBooksRfidBig = new BigDecimal("135");
		BigDecimal bookBorrowEach = new BigDecimal("6");
		BigDecimal borrowPercent = (bookBorrowEach.divide(daysTotalBorrowBooksRfidBig,4,BigDecimal.ROUND_UP).multiply(new BigDecimal("100"))).setScale(2,BigDecimal.ROUND_HALF_UP);
		System.out.println(borrowPercent.toString());
	}
	@Override
	public List<UserOperationCurveResponse> bookShelfAgeBooksStatistics(DaysQueryRequest daysQueryRequest) {
		this.initQueryRequest(daysQueryRequest);
		daysQueryRequest.setGroupCondition("0");
		//一段时间内总的借出书籍（从这个书柜里面借出的，--包括未归还的）
		String daysTotalBorrowBooksIsbn = orderTransDao.daysTotalBorrowBooksIsbn(daysQueryRequest);
		//一段时间内总的借出次数
		String daysTotalBorrowBooksRfid = orderTransDao.daysTotalBorrowBooks(daysQueryRequest);
		//年龄段借阅Isbn
		//0-3岁
		List<UserOperationCurveResponse> curveResponses = new ArrayList<UserOperationCurveResponse>();
		for(int i=0;i<4;i++) {
			daysQueryRequest.setMinAge(i*3+"");
			daysQueryRequest.setMaxAge((i+1)*3+"");
			UserOperationCurveResponse curveResponse =  this.handlerBookShelfAgeStatistics(daysQueryRequest, daysTotalBorrowBooksIsbn, daysTotalBorrowBooksRfid);
			curveResponses.add(curveResponse);
		}
		return curveResponses;
	}
	private UserOperationCurveResponse handlerBookShelfAgeStatistics(DaysQueryRequest daysQueryRequest,String daysTotalBorrowBooksIsbn,String daysTotalBorrowBooksRfid){
		List<OperationResponse> list = new ArrayList<OperationResponse>();
		//一段时间内总的借出书籍（从这个书柜里面借出的，--包括未归还的）
		String daysAgeTotalBorrowBooksIsbn = orderTransDao.daysTotalBorrowBooksIsbn(daysQueryRequest);
		//一段时间内总的借出次数
		String daysAgeTotalBorrowBooksRfid = orderTransDao.daysTotalBorrowBooks(daysQueryRequest);
		OperationResponse ageOperation = new OperationResponse();
		ageOperation.setKey("年龄段");
		ageOperation.setValue(daysQueryRequest.getMinAge()+"-"+daysQueryRequest.getMaxAge()+"岁");
		list.add(ageOperation);
		
		OperationResponse bookBorrowIsbnOperation = new OperationResponse();
		bookBorrowIsbnOperation.setKey("出借书籍");
		bookBorrowIsbnOperation.setValue(daysAgeTotalBorrowBooksIsbn);
		list.add(bookBorrowIsbnOperation);
		
		OperationResponse bookBorrowRfidOperation = new OperationResponse();
		bookBorrowRfidOperation.setKey("出借次数");
		bookBorrowRfidOperation.setValue(daysAgeTotalBorrowBooksRfid);
		list.add(bookBorrowRfidOperation);
		
		//书籍出借率
		BigDecimal bookAgeBorrowIsbn = new BigDecimal(daysAgeTotalBorrowBooksIsbn);
		BigDecimal bookBorrowIsbn = new BigDecimal(daysTotalBorrowBooksIsbn);
		BigDecimal bookAgeBorrowIsbnPercent = new BigDecimal("0");
		if(daysTotalBorrowBooksIsbn!=null&&!daysTotalBorrowBooksIsbn.equals("0")) {
			bookAgeBorrowIsbnPercent = (bookAgeBorrowIsbn.divide(bookBorrowIsbn,4,BigDecimal.ROUND_UP).multiply(new BigDecimal("100"))).setScale(2,BigDecimal.ROUND_HALF_UP);
		}
		OperationResponse bookAgeBorrowIsbnPercentOperation = new OperationResponse();
		bookAgeBorrowIsbnPercentOperation.setKey("书籍出借率");
		bookAgeBorrowIsbnPercentOperation.setValue(bookAgeBorrowIsbnPercent.toString()+"%");
		list.add(bookAgeBorrowIsbnPercentOperation);
		//次数出借率
		BigDecimal bookAgeBorrowRfid = new BigDecimal(daysAgeTotalBorrowBooksRfid);
		BigDecimal bookBorrowRfid = new BigDecimal(daysTotalBorrowBooksRfid);
		BigDecimal bookAgeBorrowRfidPercent = new BigDecimal("0");
		if(daysTotalBorrowBooksRfid!=null&&!daysTotalBorrowBooksRfid.equals("0")) {
			bookAgeBorrowRfidPercent = (bookAgeBorrowRfid.divide(bookBorrowRfid,4,BigDecimal.ROUND_UP).multiply(new BigDecimal("100"))).setScale(2,BigDecimal.ROUND_HALF_UP);
		}
		OperationResponse bookAgeBorrowRfidPercentOperation = new OperationResponse();
		bookAgeBorrowRfidPercentOperation.setKey("次数出借率");
		bookAgeBorrowRfidPercentOperation.setValue(bookAgeBorrowRfidPercent.toString()+"%");
		list.add(bookAgeBorrowRfidPercentOperation);
		
		UserOperationCurveResponse curveResponse = new UserOperationCurveResponse();
		curveResponse.setDateStr("");
		curveResponse.setOperationResponses(list);
		return curveResponse;
	}

	@Override
	public List<OperationResponse> bookTotalStatistics(DaysQueryRequest daysQueryRequest) {
		//TODO 判断时间是否为天；
		long diff = daysQueryRequest.getQueryEndTime().getTime() - daysQueryRequest.getQueryStartTime().getTime();
		long days = diff / (1000 * 60 * 60 * 24);  
		if(days>=1) {
			daysQueryRequest.setGroupCondition("0");
		}else {
			daysQueryRequest.setGroupCondition("1");
		}
		this.initQueryRequest(daysQueryRequest);
		List<OperationResponse> list = new ArrayList<OperationResponse>();
		BorrowStatistics borrowStatistics = orderTransDao.daysBorrowTimes(daysQueryRequest);
		OperationResponse borrowStatisticsResponse = new OperationResponse();
		borrowStatisticsResponse.setKey("出借次数");
		borrowStatisticsResponse.setValue(borrowStatistics.getBorrowTimes());
		list.add(borrowStatisticsResponse);
		//一段时间内在借书籍
		List<UserOperationCurveResponse> curveResponses = new ArrayList<UserOperationCurveResponse>();
		int times = 0;
		if(days<=1) {//直接24小时
			daysQueryRequest.setGroupCondition("1");
			String dateStr = DateFormatUtil.formatDate(new Date());
			Date starTime = DateFormatUtil.parseDate(dateStr);
			
			daysQueryRequest.setOriginalQueryStartTime(starTime);
			daysQueryRequest.setQueryStartTime(starTime);
			
			String endDateStr = dateStr+" 23:59:59";
			Date endTime = DateFormatUtil.parseDatePattern(endDateStr, DateFormatUtil.DATETIME_PATTERN);
			daysQueryRequest.setOriginalQueryStartTime(endTime);
			daysQueryRequest.setQueryStartTime(endTime);
			
			//List<StatisticsEntity> statisticsEntitys = statisticsDao.selectDaysStatistics(daysQueryRequest);
			times = 24;
			for(int i=0;i<times;i++) {
				this.calculateEachQueryRequest(daysQueryRequest, new BigDecimal("1"), 0,i,false);
				UserOperationCurveResponse userOperationCurveResponse = this.handlerBooksEachStatistics(daysQueryRequest);
				curveResponses.add(userOperationCurveResponse);
			}
		}else if( days>1 && days<=30) {//每天
			times = 7;
			daysQueryRequest.setGroupCondition("0");
			times = (int) days+1;
			//List<StatisticsEntity> statisticsEntitys = statisticsDao.selectDaysStatistics(daysQueryRequest);
			for(int i=0;i<days;i++) {
				this.calculateEachQueryRequest(daysQueryRequest, new BigDecimal("1"), 1,i,false);
				UserOperationCurveResponse userOperationCurveResponse = this.handlerBooksEachStatistics(daysQueryRequest);
				curveResponses.add(userOperationCurveResponse);
			}
		}else if(days>30 && days<=182) {//每周
			daysQueryRequest.setGroupCondition("0");
			times = (int) (days/7)+1;
			//List<StatisticsEntity> statisticsEntitys = statisticsDao.selectDaysStatistics(daysQueryRequest);
			for(int i=0;i<times;i++) {
				if(i==times-1) {
					this.calculateEachQueryRequest(daysQueryRequest, new BigDecimal("6"), 1,i,true);
				}else {
					this.calculateEachQueryRequest(daysQueryRequest, new BigDecimal("6"), 1,i,false);
				}
				UserOperationCurveResponse userOperationCurveResponse = this.handlerBooksEachStatistics( daysQueryRequest);
				curveResponses.add(userOperationCurveResponse);
			}
		}else if(days>182) {//每月
			daysQueryRequest.setGroupCondition("0");
			times = (int) (days/30)+1;
			//List<StatisticsEntity> statisticsEntitys = statisticsDao.selectDaysStatistics(daysQueryRequest);
			for(int i=0;i<times;i++) {
				if(i==times-1) {
					this.calculateEachQueryRequest(daysQueryRequest, new BigDecimal("29"), 1,i,true);
				}else {
					this.calculateEachQueryRequest(daysQueryRequest, new BigDecimal("29"), 1,i,false);
				}
				UserOperationCurveResponse userOperationCurveResponse = this.handlerBooksEachStatistics(daysQueryRequest);
				curveResponses.add(userOperationCurveResponse);
			}
		}
		
		//BorrowStatistics borrowTimeStatistics = orderTransDao.daysCurrentBorrowBooks(daysQueryRequest);
		int books = 0;
		for(UserOperationCurveResponse userOperationCurveResponse : curveResponses) {
			String booksStr = userOperationCurveResponse.getOperationResponses().get(1).getValue();
			books = books+Integer.valueOf(booksStr);
		}
		OperationResponse borrowTimeStatisticsResponse = new OperationResponse();
		borrowTimeStatisticsResponse.setKey("在借书籍");
		borrowTimeStatisticsResponse.setValue(books/times+"");
		list.add(borrowTimeStatisticsResponse);
		daysQueryRequest.setQueryStartTime(daysQueryRequest.getOriginalQueryStartTime());
		//一段时间内归还书籍
		BorrowStatistics returnBooksStatistics = orderTransDao.daysReturnBooks(daysQueryRequest);
		OperationResponse returnBooksStatisticsResponse = new OperationResponse();
		returnBooksStatisticsResponse.setKey("已归还书籍");
		returnBooksStatisticsResponse.setValue(returnBooksStatistics.getReturnBooks());
		list.add(returnBooksStatisticsResponse);
		//在柜书籍(当前)
		BorrowStatistics inGridBooks  = bookEntityDao.inGridBooks(daysQueryRequest);
		OperationResponse inGridBooksResponse = new OperationResponse();
		inGridBooksResponse.setKey("在柜书籍");
		inGridBooksResponse.setValue(inGridBooks.getInGridBooks());
		list.add(inGridBooksResponse);
		return list;
	}
	/**
	 * 
	 * @Method:handlerBooksEachStatistics
	 * @Description:
	 * @Time 2018年3月6日 下午3:49:10
	 * @author: Tom
	 * @param statisticsEntity
	 * @param daysQueryRequest
	 * @return
	 */
	private UserOperationCurveResponse handlerBooksEachStatistics(DaysQueryRequest daysQueryRequest) {
		List<OperationResponse> operationResponses = new ArrayList<OperationResponse>();
		//出借次数
		BorrowStatistics borrowStatistics = orderTransDao.daysBorrowTimes(daysQueryRequest);
		OperationResponse borrowStatisticsResponse = new OperationResponse();
		borrowStatisticsResponse.setKey("出借次数");
		borrowStatisticsResponse.setValue(borrowStatistics.getBorrowTimes());
		operationResponses.add(borrowStatisticsResponse);
		//一段时间内在借书籍
		BorrowStatistics borrowTimeStatistics = orderTransDao.daysCurrentBorrowBooks(daysQueryRequest);
		OperationResponse borrowTimeStatisticsResponse = new OperationResponse();
		borrowTimeStatisticsResponse.setKey("在借书籍");
		borrowTimeStatisticsResponse.setValue(borrowTimeStatistics.getCurrentBorrowBooks());
		operationResponses.add(borrowTimeStatisticsResponse);
		
		//一段时间内归还书籍
		BorrowStatistics returnBooksStatistics = orderTransDao.daysReturnBooks(daysQueryRequest);
		OperationResponse returnBooksStatisticsResponse = new OperationResponse();
		returnBooksStatisticsResponse.setKey("已归还书籍");
		returnBooksStatisticsResponse.setValue(returnBooksStatistics.getReturnBooks());
		operationResponses.add(returnBooksStatisticsResponse);

		UserOperationCurveResponse curveResponse = new UserOperationCurveResponse();
		curveResponse.setDateStr(DateFormatUtil.formateDateToString(daysQueryRequest.getQueryStartTime(), DateFormatUtil.DATE_PATTERN_LEAN));
		curveResponse.setOperationResponses(operationResponses);
		
		return curveResponse;
	}
	@Override
	public List<UserOperationCurveResponse> bookEachStatistics(DaysQueryRequest daysQueryRequest) {
		List<UserOperationCurveResponse> list = new ArrayList<>();
		this.initQueryRequest(daysQueryRequest);
		Date queryEndTime = daysQueryRequest.getQueryEndTime();
		Date queryStartTime = daysQueryRequest.getQueryStartTime();
		if(queryStartTime==null) {
			return null;
		}
		long diff = queryEndTime.getTime() - queryStartTime.getTime();
		long days = diff / (1000 * 60 * 60 * 24)+1;  
		if(days<=1) {//直接24小时
			daysQueryRequest.setGroupCondition("1");
			String dateStr = DateFormatUtil.formatDate(daysQueryRequest.getQueryStartTime());
			Date starTime = DateFormatUtil.parseDate(dateStr);
			
			daysQueryRequest.setOriginalQueryStartTime(starTime);
			daysQueryRequest.setQueryStartTime(starTime);
			
			String endDateStr = dateStr+" 23:59:59";
			Date endTime = DateFormatUtil.parseDatePattern(endDateStr, DateFormatUtil.DATETIME_PATTERN);
			daysQueryRequest.setOriginalQueryEndTime(endTime);
			daysQueryRequest.setQueryEndTime(endTime);
			
			//List<StatisticsEntity> statisticsEntitys = statisticsDao.selectDaysStatistics(daysQueryRequest);
			for(int i=0;i<23;i++) {
				this.calculateEachQueryRequest(daysQueryRequest, new BigDecimal("1"), 0,i,false);
				UserOperationCurveResponse userOperationCurveResponse = this.handlerBooksEachStatistics(daysQueryRequest);
				list.add(userOperationCurveResponse);
			}
		}else if( days>1 && days<=30) {//每天
			daysQueryRequest.setGroupCondition("0");
			//List<StatisticsEntity> statisticsEntitys = statisticsDao.selectDaysStatistics(daysQueryRequest);
			for(int i=0;i<days+1;i++) {
				this.calculateEachQueryRequest(daysQueryRequest, new BigDecimal("1"), 1,i,false);
				UserOperationCurveResponse userOperationCurveResponse = this.handlerBooksEachStatistics(daysQueryRequest);
				list.add(userOperationCurveResponse);
			}
		}else if(days>30 && days<=182) {//每周
			daysQueryRequest.setGroupCondition("0");
			int times = (int) (days/7)+1;
			//List<StatisticsEntity> statisticsEntitys = statisticsDao.selectDaysStatistics(daysQueryRequest);
			for(int i=0;i<times;i++) {
				if(i==times-1) {
					this.calculateEachQueryRequest(daysQueryRequest, new BigDecimal("6"), 1,i,true);
				}else {
					this.calculateEachQueryRequest(daysQueryRequest, new BigDecimal("6"), 1,i,false);
				}
				UserOperationCurveResponse userOperationCurveResponse = this.handlerBooksEachStatistics(daysQueryRequest);
				list.add(userOperationCurveResponse);
			}
		}else if(days>182) {//每月
			daysQueryRequest.setGroupCondition("0");
			int times = (int) (days/30)+1;
			//List<StatisticsEntity> statisticsEntitys = statisticsDao.selectDaysStatistics(daysQueryRequest);
			for(int i=0;i<times;i++) {
				if(i==times-1) {
					this.calculateEachQueryRequest(daysQueryRequest, new BigDecimal("29"), 1,i,true);
				}else {
					this.calculateEachQueryRequest(daysQueryRequest, new BigDecimal("29"), 1,i,false);
				}
				UserOperationCurveResponse userOperationCurveResponse = this.handlerBooksEachStatistics(daysQueryRequest);
				list.add(userOperationCurveResponse);
			}
		}
		return list;
	}

	@Override
	public List<UserOperationCurveResponse> daysUserTimeDetailDataStatistics(DaysQueryRequest daysQueryRequest) {
		//判断时间是否为天；
		daysQueryRequest.setQueryStartTime(daysQueryRequest.getOriginalQueryStartTime());
		daysQueryRequest.setQueryEndTime(daysQueryRequest.getOriginalQueryEndTime());
		long diff = daysQueryRequest.getQueryEndTime().getTime() - daysQueryRequest.getQueryStartTime().getTime();
		this.initQueryRequest(daysQueryRequest);
		long days = diff / (1000 * 60 * 60 * 24)+1;  
		daysQueryRequest.setGroupCondition("1");
		List<UserOperationCurveResponse> userOperationCurveResponses = new ArrayList<>();
		for(int i=0;i<days;i++) {
			List<OperationResponse> operationResponses = new ArrayList<OperationResponse>();
			this.caculateTimeDetailEachQueryRequest(daysQueryRequest, i);
			//注册用户
			UserStatistics daysUser = userInfoDao.daysUser(daysQueryRequest);
			OperationResponse dayUserOperation = new OperationResponse();
			dayUserOperation.setKey("注册用户");
			dayUserOperation.setValue(daysUser.getAddUser());
			operationResponses.add(dayUserOperation);
			//有效押金用户
			CapitalStatistics daysAvailableDepositUser = userChargeLogDao.daysAvailableDepositUser(daysQueryRequest);//daysTotalDepositUser
			OperationResponse dayDepositUserOperation = new OperationResponse();
			dayDepositUserOperation.setKey("有效押金用户");
			dayDepositUserOperation.setValue(daysAvailableDepositUser.getAvailableDepositUser());
			operationResponses.add(dayDepositUserOperation);
			//充值用户
			CapitalStatistics daysCashUser = userChargeLogDao.daysCashUser(daysQueryRequest);
			OperationResponse dayCashUserOperation = new OperationResponse();
			dayCashUserOperation.setKey("充值用户");
			dayCashUserOperation.setValue(daysCashUser.getCashUser());
			operationResponses.add(dayCashUserOperation);
			//月卡会员
			VipStatistics vipMonthUserStatistics = vipMemberDao.daysVipMonth(daysQueryRequest);
			OperationResponse vipMonthUserOperation = new OperationResponse();
			vipMonthUserOperation.setKey("月卡会员");
			vipMonthUserOperation.setValue(vipMonthUserStatistics.getVipMonthUsers());
			operationResponses.add(vipMonthUserOperation);
			//年卡会员
			VipStatistics vipYearUserStatistics = vipMemberDao.daysVipYear(daysQueryRequest);
			OperationResponse vipYearUserOperation = new OperationResponse();
			vipYearUserOperation.setKey("年卡会员");
			vipYearUserOperation.setValue(vipYearUserStatistics.getVipYearUsers());
			operationResponses.add(vipYearUserOperation);
			//退押金用户
			CapitalStatistics dayRefundDepositUser = userChargeLogDao.daysRefundDepositUser(daysQueryRequest);//daysTotalRefundDepositUser
			OperationResponse dayRefundDepositUserOperation = new OperationResponse();
			dayRefundDepositUserOperation.setKey("退押金用户");
			dayRefundDepositUserOperation.setValue(dayRefundDepositUser.getRefundDepositUser());
			operationResponses.add(dayRefundDepositUserOperation);
			//借阅用户
			BorrowStatistics borrowStatistics = orderTransDao.daysBorrowUsers(daysQueryRequest);
			OperationResponse dayBorrowedUserOperation = new OperationResponse();
			dayBorrowedUserOperation.setKey("借阅用户(活跃用户)");
			dayBorrowedUserOperation.setValue(borrowStatistics.getBorrowUsers());
			operationResponses.add(dayBorrowedUserOperation);
			
			UserOperationCurveResponse curveResponse = new UserOperationCurveResponse();
			curveResponse.setDateStr(DateFormatUtil.formateDateToString(daysQueryRequest.getQueryStartTime(), DateFormatUtil.DATE_PATTERN_LEAN));
			curveResponse.setOperationResponses(operationResponses);
			userOperationCurveResponses.add(curveResponse);
		}
		return userOperationCurveResponses;
	}

	@Override
	public List<UserOperationCurveResponse> daysCapitalTimeDetailDataStatistics(DaysQueryRequest daysQueryRequest) {
		//判断时间是否为天；
		daysQueryRequest.setQueryStartTime(daysQueryRequest.getOriginalQueryStartTime());
		daysQueryRequest.setQueryEndTime(daysQueryRequest.getOriginalQueryEndTime());
		long diff = daysQueryRequest.getQueryEndTime().getTime() - daysQueryRequest.getQueryStartTime().getTime();
		this.initQueryRequest(daysQueryRequest);
		long days = diff / (1000 * 60 * 60 * 24)+1;  
		daysQueryRequest.setGroupCondition("1");
		List<UserOperationCurveResponse> userOperationCurveResponses = new ArrayList<>();
		for(int i=0;i<days;i++) {
			List<OperationResponse> operationResponses = new ArrayList<OperationResponse>();
			this.caculateTimeDetailEachQueryRequest(daysQueryRequest, i);
			//有效押金
			CapitalStatistics daysAvailableDeposit = userChargeLogDao.daysAvailableDeposit(daysQueryRequest);//daysTotalDepositUser
			OperationResponse dayDepositUserOperation = new OperationResponse();
			dayDepositUserOperation.setKey("缴纳押金");
			dayDepositUserOperation.setValue(daysAvailableDeposit.getAvailableDeposit());
			operationResponses.add(dayDepositUserOperation);
			//充值余额(有效)
			CapitalStatistics daysCash = userChargeLogDao.daysCash(daysQueryRequest);
			OperationResponse dayCashAmountOperation = new OperationResponse();
			dayCashAmountOperation.setKey("充值余额(有效)");
			dayCashAmountOperation.setValue(daysCash.getCash());
			operationResponses.add(dayCashAmountOperation);
			//充值余额(活动赠送)
			CapitalStatistics daysActiveCash = accountCashLogDao.daysActiveCash(daysQueryRequest);
			OperationResponse dayActiveCashAmountOperation = new OperationResponse();
			dayActiveCashAmountOperation.setKey("充值余额(活动赠送)");
			dayActiveCashAmountOperation.setValue(daysActiveCash.getActiveCash());
			operationResponses.add(dayActiveCashAmountOperation);
			//充值余额(总计)
			OperationResponse dayTotalCashAmountOperation = new OperationResponse();
			dayTotalCashAmountOperation.setKey("充值余额(总计)");
			dayTotalCashAmountOperation.setValue(new BigDecimal(daysCash.getCash()).add(new BigDecimal(daysActiveCash.getActiveCash())).toString() );
			operationResponses.add(dayTotalCashAmountOperation);
			//年卡充值余额(有效)
			VipStatistics vipAvailableYearStatistics = vipMemberLogDao.daysVipAvailableCashYear(daysQueryRequest);
			OperationResponse daysAvailableVipCashYearOperation = new OperationResponse();
			daysAvailableVipCashYearOperation.setKey("年卡充值金额(有效)");
			daysAvailableVipCashYearOperation.setValue(vipAvailableYearStatistics.getVipAvailableYearCash());
			operationResponses.add(daysAvailableVipCashYearOperation);
			//年卡充值余额(活动赠送)
			VipStatistics vipTotalYearStatistics = vipMemberLogDao.daysVipCashYear(daysQueryRequest);
			OperationResponse daysActiveVipCashYearOperation = new OperationResponse();
			daysActiveVipCashYearOperation.setKey("年卡充值金额(活动赠送)");
			daysActiveVipCashYearOperation.setValue(new BigDecimal(vipTotalYearStatistics.getVipYearCash()).subtract(new BigDecimal(vipAvailableYearStatistics.getVipAvailableYearCash())).toString());
			operationResponses.add(daysActiveVipCashYearOperation);
			//年卡充值余额(总计)
			OperationResponse daysVipCashYearOperation = new OperationResponse();
			daysVipCashYearOperation.setKey("年卡充值金额(总计)");
			daysVipCashYearOperation.setValue(vipTotalYearStatistics.getVipYearCash());
			operationResponses.add(daysVipCashYearOperation);
			//月卡充值金额(有效)
			VipStatistics vipAvailableMonthStatistics = vipMemberLogDao.daysVipAvailableCashMonth(daysQueryRequest);
			OperationResponse daysAvailableVipCashMonthOperation = new OperationResponse();
			daysAvailableVipCashMonthOperation.setKey("月卡充值金额(有效)");
			daysAvailableVipCashMonthOperation.setValue(vipAvailableMonthStatistics.getVipAvailableMonthCash());
			operationResponses.add(daysAvailableVipCashMonthOperation);
			
			//月卡充值金额(活动赠送)
			VipStatistics vipTotalMonthStatistics = vipMemberLogDao.daysVipCashMonth(daysQueryRequest);
			OperationResponse daysActiveVipCashMonthOperation = new OperationResponse();
			daysActiveVipCashMonthOperation.setKey("月卡充值金额(活动赠送)");
			daysActiveVipCashMonthOperation.setValue(new BigDecimal(vipTotalMonthStatistics.getVipMonthCash()).subtract(new BigDecimal(vipAvailableMonthStatistics.getVipAvailableMonthCash())).toString());
			operationResponses.add(daysActiveVipCashMonthOperation);
			//月卡充值金额(总计)
			OperationResponse daysTotalVipCashMonthOperation = new OperationResponse();
			daysTotalVipCashMonthOperation.setKey("月卡充值金额(活动赠送)");
			daysTotalVipCashMonthOperation.setValue(vipTotalMonthStatistics.getVipMonthCash());
			operationResponses.add(daysTotalVipCashMonthOperation);
			//活动支出
			CapitalStatistics daysActiveCashStatistics =  accountCashLogDao.daysActiveCash(daysQueryRequest);
			OperationResponse daysTotalActiveCashOperation = new OperationResponse();
			daysTotalActiveCashOperation.setKey("活动支出");
			daysTotalActiveCashOperation.setValue(daysActiveCashStatistics.getActiveCash());
			operationResponses.add(daysTotalActiveCashOperation);
			//退押金
			CapitalStatistics dayRefundDeposit = userChargeLogDao.daysRefundDeposit(daysQueryRequest);//daysTotalRefundDepositUser
			OperationResponse daysRefundDepositOperation = new OperationResponse();
			daysRefundDepositOperation.setKey("已退押金");
			daysRefundDepositOperation.setValue(dayRefundDeposit.getRefundDeposit());
			operationResponses.add(daysRefundDepositOperation);

			UserOperationCurveResponse curveResponse = new UserOperationCurveResponse();
			curveResponse.setDateStr(DateFormatUtil.formateDateToString(daysQueryRequest.getQueryStartTime(), DateFormatUtil.DATE_PATTERN_LEAN));
			curveResponse.setOperationResponses(operationResponses);
			userOperationCurveResponses.add(curveResponse);
		}
		return userOperationCurveResponses;
	
	}

	@Override
	public List<UserOperationCurveResponse> daysBookShelfTimeDetailDataStatistics(DaysQueryRequest daysQueryRequest) {
		//判断时间是否为天；
		daysQueryRequest.setQueryStartTime(daysQueryRequest.getOriginalQueryStartTime());
		daysQueryRequest.setQueryEndTime(daysQueryRequest.getOriginalQueryEndTime());
		long diff = daysQueryRequest.getQueryEndTime().getTime() - daysQueryRequest.getQueryStartTime().getTime();
		this.initQueryRequest(daysQueryRequest);
		long days = diff / (1000 * 60 * 60 * 24)+1;  
		daysQueryRequest.setGroupCondition("1");
		List<UserOperationCurveResponse> userOperationCurveResponses = new ArrayList<>();
		for(int i=0;i<days;i++) {
			List<OperationResponse> operationResponses = new ArrayList<OperationResponse>();
			this.caculateTimeDetailEachQueryRequest(daysQueryRequest, i);
			UserStatistics daysUserStatistics = userInfoDao.daysUser(daysQueryRequest);
			//注册用户
			OperationResponse daysUserOperation = new OperationResponse();
			daysUserOperation.setKey("注册用户");
			daysUserOperation.setValue(daysUserStatistics.getAddUser());
			operationResponses.add(daysUserOperation);
			//有效押金用户
			CapitalStatistics daysAvailableDepositUser = userChargeLogDao.daysAvailableDepositUser(daysQueryRequest);
			OperationResponse dayDepositUserOperation = new OperationResponse();
			dayDepositUserOperation.setKey("缴纳押金用户");
			dayDepositUserOperation.setValue(daysAvailableDepositUser.getAvailableDepositUser());
			operationResponses.add(dayDepositUserOperation);
			//有效押金金额
			CapitalStatistics daysAvailableDeposit = userChargeLogDao.daysAvailableDeposit(daysQueryRequest);
			OperationResponse dayDepositOperation = new OperationResponse();
			dayDepositOperation.setKey("有效押金金额");
			dayDepositOperation.setValue(daysAvailableDeposit.getAvailableDeposit());
			operationResponses.add(dayDepositOperation);
			//充值余额(有效)
			CapitalStatistics daysCash = userChargeLogDao.daysCash(daysQueryRequest);
			OperationResponse dayCashAmountOperation = new OperationResponse();
			dayCashAmountOperation.setKey("充值余额(有效)");
			dayCashAmountOperation.setValue(daysCash.getCash());
			operationResponses.add(dayCashAmountOperation);
			//退押金用户数
			CapitalStatistics daysRefundDepositUser = userChargeLogDao.daysRefundDepositUser(daysQueryRequest);
			OperationResponse dayRefundDepositUsersOperation = new OperationResponse();
			dayRefundDepositUsersOperation.setKey("退押金用户数");
			dayRefundDepositUsersOperation.setValue(daysRefundDepositUser.getRefundDepositUser());
			operationResponses.add(dayRefundDepositUsersOperation);
			//年卡会员(有效)
			VipStatistics vipAvailableYearsUser = vipMemberDao.daysAvailableVipYear(daysQueryRequest);
			OperationResponse daysVipYearUserOperation = new OperationResponse();
			daysVipYearUserOperation.setKey("年卡会员(有效)");
			daysVipYearUserOperation.setValue(vipAvailableYearsUser.getVipAvailableYearUsers());
			operationResponses.add(daysVipYearUserOperation);
			//月卡会员(有效)
			VipStatistics vipAvailableMonthUser = vipMemberDao.daysAvailableVipMonth(daysQueryRequest);
			OperationResponse daysVipMonthUserOperation = new OperationResponse();
			daysVipMonthUserOperation.setKey("月卡会员(有效)");
			daysVipMonthUserOperation.setValue(vipAvailableMonthUser.getVipAvailableMonthUsers());
			operationResponses.add(daysVipMonthUserOperation);
			//借阅书籍
			BorrowStatistics borrowStatistics = orderTransDao.daysBorrowBooks(daysQueryRequest);
			OperationResponse daysBorrowBooksOperation = new OperationResponse();
			daysBorrowBooksOperation.setKey("出借书籍数");
			daysBorrowBooksOperation.setValue(borrowStatistics.getBorrowBooks());
			operationResponses.add(daysBorrowBooksOperation);
			
			UserOperationCurveResponse curveResponse = new UserOperationCurveResponse();
			curveResponse.setDateStr(DateFormatUtil.formateDateToString(daysQueryRequest.getQueryStartTime(), DateFormatUtil.DATE_PATTERN_LEAN));
			curveResponse.setOperationResponses(operationResponses);
			userOperationCurveResponses.add(curveResponse);
		}
		return userOperationCurveResponses;
	}

	@Override
	public List<OperationResponse> daysAgeUserTotalStatistics(DaysQueryRequest daysQueryRequest) {
		//判断时间是否为天；
		long diff = daysQueryRequest.getQueryEndTime().getTime() - daysQueryRequest.getQueryStartTime().getTime();
		//判断是否真的小于1天
		String dateStartStr = DateFormatUtil.formatDate(daysQueryRequest.getQueryStartTime());
		String dateEndStr = DateFormatUtil.formatDate(daysQueryRequest.getQueryEndTime());
		this.initQueryRequest(daysQueryRequest);
		long days = diff / (1000 * 60 * 60 * 24)+1;  
		if(days<1) {
			if(dateStartStr.equals(dateEndStr)) {
				days = 1;
			}else {
				days = 2;
			}
		}
		daysQueryRequest.setGroupCondition("1");
		List<OperationResponse> operationResponses = new ArrayList<OperationResponse>();
		//各年龄段数据统计
		daysQueryRequest.setQueryEndTime(daysQueryRequest.getOriginalQueryEndTime());
		daysQueryRequest.setOriginalQueryStartTime(daysQueryRequest.getOriginalQueryStartTime());
		
		daysQueryRequest.setMinAge("0");
		daysQueryRequest.setMaxAge("3");
		String daysBorrowUsersAgeVal03 = orderTransDao.daysTotalBorrowUsers(daysQueryRequest);
		OperationResponse dayBorrowUsersAge03 = new OperationResponse();
		dayBorrowUsersAge03.setKey("0-3岁");
		dayBorrowUsersAge03.setValue(daysBorrowUsersAgeVal03);
		operationResponses.add(dayBorrowUsersAge03);
		
		daysQueryRequest.setMinAge("3");
		daysQueryRequest.setMaxAge("6");
		String daysBorrowUsersAgeVal36 = orderTransDao.daysTotalBorrowUsers(daysQueryRequest);
		OperationResponse daysBorrowUsersAge36 = new OperationResponse();
		daysBorrowUsersAge36.setKey("3-6岁");
		daysBorrowUsersAge36.setValue(daysBorrowUsersAgeVal36);
		operationResponses.add(daysBorrowUsersAge36);
		
		daysQueryRequest.setMinAge("6");
		daysQueryRequest.setMaxAge("9");
		String daysBorrowUsersAgeVal69 = orderTransDao.daysTotalBorrowUsers(daysQueryRequest);
		OperationResponse daysBorrowUsersAge69 = new OperationResponse();
		daysBorrowUsersAge69.setKey("6-9岁");
		daysBorrowUsersAge69.setValue(daysBorrowUsersAgeVal69);
		operationResponses.add(daysBorrowUsersAge69);
		
		daysQueryRequest.setMinAge("9");
		daysQueryRequest.setMaxAge("12");
		String daysBorrowUsersAgeVal912 = orderTransDao.daysTotalBorrowUsers(daysQueryRequest);
		OperationResponse daysBorrowUsersAge912 = new OperationResponse();
		daysBorrowUsersAge912.setKey("9-12岁");
		daysBorrowUsersAge912.setValue(daysBorrowUsersAgeVal912);
		operationResponses.add(daysBorrowUsersAge912);
		return operationResponses;
	}

	@Override
	public List<UserOperationCurveResponse> daysAgeUserTimeDetailDataStatistics(DaysQueryRequest daysQueryRequest) {
		//判断时间是否为天；
		daysQueryRequest.setQueryStartTime(daysQueryRequest.getOriginalQueryStartTime());
		daysQueryRequest.setQueryEndTime(daysQueryRequest.getOriginalQueryEndTime());
		long diff = daysQueryRequest.getQueryEndTime().getTime() - daysQueryRequest.getQueryStartTime().getTime();
		this.initQueryRequest(daysQueryRequest);
		long days = diff / (1000 * 60 * 60 * 24)+1;  
		daysQueryRequest.setGroupCondition("1");
		List<UserOperationCurveResponse> userOperationCurveResponses = new ArrayList<>();
		for(int i=0;i<days;i++) {
			List<OperationResponse> operationResponses = new ArrayList<OperationResponse>();
			this.caculateTimeDetailEachQueryRequest(daysQueryRequest, i);
			
			daysQueryRequest.setMinAge("0");
			daysQueryRequest.setMaxAge("3");
			String daysBorrowUsersAgeVal03 = orderTransDao.daysTotalBorrowUsers(daysQueryRequest);
			OperationResponse dayBorrowUsersAge03 = new OperationResponse();
			dayBorrowUsersAge03.setKey("0-3岁");
			dayBorrowUsersAge03.setValue(daysBorrowUsersAgeVal03);
			operationResponses.add(dayBorrowUsersAge03);
			
			daysQueryRequest.setMinAge("3");
			daysQueryRequest.setMaxAge("6");
			String daysBorrowUsersAgeVal36 = orderTransDao.daysTotalBorrowUsers(daysQueryRequest);
			OperationResponse daysBorrowUsersAge36 = new OperationResponse();
			daysBorrowUsersAge36.setKey("3-6岁");
			daysBorrowUsersAge36.setValue(daysBorrowUsersAgeVal36);
			operationResponses.add(daysBorrowUsersAge36);
			
			daysQueryRequest.setMinAge("6");
			daysQueryRequest.setMaxAge("9");
			String daysBorrowUsersAgeVal69 = orderTransDao.daysTotalBorrowUsers(daysQueryRequest);
			OperationResponse daysBorrowUsersAge69 = new OperationResponse();
			daysBorrowUsersAge69.setKey("6-9岁");
			daysBorrowUsersAge69.setValue(daysBorrowUsersAgeVal69);
			operationResponses.add(daysBorrowUsersAge69);
			
			daysQueryRequest.setMinAge("9");
			daysQueryRequest.setMaxAge("12");
			String daysBorrowUsersAgeVal912 = orderTransDao.daysTotalBorrowUsers(daysQueryRequest);
			OperationResponse daysBorrowUsersAge912 = new OperationResponse();
			daysBorrowUsersAge912.setKey("9-12岁");
			daysBorrowUsersAge912.setValue(daysBorrowUsersAgeVal912);
			operationResponses.add(daysBorrowUsersAge912);
			
			UserOperationCurveResponse curveResponse = new UserOperationCurveResponse();
			curveResponse.setDateStr(DateFormatUtil.formateDateToString(daysQueryRequest.getQueryStartTime(), DateFormatUtil.DATE_PATTERN_LEAN));
			curveResponse.setOperationResponses(operationResponses);
			userOperationCurveResponses.add(curveResponse);
		}
		return userOperationCurveResponses;
	}

	private UserOperationCurveResponse handlerAgetUserStatistics(DaysQueryRequest daysQueryRequest) {
		List<OperationResponse> operationResponses = new ArrayList<OperationResponse>();
		
		daysQueryRequest.setMinAge("0");
		daysQueryRequest.setMaxAge("3");
		String daysBorrowUsersAgeVal03 = orderTransDao.daysTotalBorrowUsers(daysQueryRequest);
		OperationResponse dayBorrowUsersAge03 = new OperationResponse();
		dayBorrowUsersAge03.setKey("0-3岁");
		dayBorrowUsersAge03.setValue(daysBorrowUsersAgeVal03);
		operationResponses.add(dayBorrowUsersAge03);
		
		daysQueryRequest.setMinAge("3");
		daysQueryRequest.setMaxAge("6");
		String daysBorrowUsersAgeVal36 = orderTransDao.daysTotalBorrowUsers(daysQueryRequest);
		OperationResponse daysBorrowUsersAge36 = new OperationResponse();
		daysBorrowUsersAge36.setKey("3-6岁");
		daysBorrowUsersAge36.setValue(daysBorrowUsersAgeVal36);
		operationResponses.add(daysBorrowUsersAge36);
		
		daysQueryRequest.setMinAge("6");
		daysQueryRequest.setMaxAge("9");
		String daysBorrowUsersAgeVal69 = orderTransDao.daysTotalBorrowUsers(daysQueryRequest);
		OperationResponse daysBorrowUsersAge69 = new OperationResponse();
		daysBorrowUsersAge69.setKey("6-9岁");
		daysBorrowUsersAge69.setValue(daysBorrowUsersAgeVal69);
		operationResponses.add(daysBorrowUsersAge69);
		
		daysQueryRequest.setMinAge("9");
		daysQueryRequest.setMaxAge("12");
		String daysBorrowUsersAgeVal912 = orderTransDao.daysTotalBorrowUsers(daysQueryRequest);
		OperationResponse daysBorrowUsersAge912 = new OperationResponse();
		daysBorrowUsersAge912.setKey("9-12岁");
		daysBorrowUsersAge912.setValue(daysBorrowUsersAgeVal912);
		operationResponses.add(daysBorrowUsersAge912);
		
		UserOperationCurveResponse curveResponse = new UserOperationCurveResponse();
		curveResponse.setDateStr(DateFormatUtil.formateDateToString(daysQueryRequest.getQueryStartTime(), DateFormatUtil.DATE_PATTERN_LEAN));
		curveResponse.setOperationResponses(operationResponses);
		
		return curveResponse;
	}
	
	@Override
	public List<UserOperationCurveResponse> dayAgesUserEachStatistics(DaysQueryRequest daysQueryRequest) {
		daysQueryRequest.setQueryStartTime(daysQueryRequest.getOriginalQueryStartTime());
		daysQueryRequest.setQueryEndTime(daysQueryRequest.getOriginalQueryEndTime());
		List<UserOperationCurveResponse> list = new ArrayList<>();
		this.initQueryRequest(daysQueryRequest);
		Date queryEndTime = daysQueryRequest.getQueryEndTime();
		Date queryStartTime = daysQueryRequest.getQueryStartTime();
		if(queryStartTime==null) {
			return null;
		}
		long diff = queryEndTime.getTime() - queryStartTime.getTime();
		long days = diff / (1000 * 60 * 60 * 24)+1;  
		if(days<=1) {//直接24小时
			daysQueryRequest.setGroupCondition("1");
			String dateStr = DateFormatUtil.formatDate(daysQueryRequest.getQueryStartTime());
			Date starTime = DateFormatUtil.parseDate(dateStr);
			
			daysQueryRequest.setOriginalQueryStartTime(starTime);
			daysQueryRequest.setQueryStartTime(starTime);
			
			String endDateStr = dateStr+" 23:59:59";
			Date endTime = DateFormatUtil.parseDatePattern(endDateStr, DateFormatUtil.DATETIME_PATTERN);
			daysQueryRequest.setOriginalQueryEndTime(endTime);
			daysQueryRequest.setQueryEndTime(endTime);
			
			//List<StatisticsEntity> statisticsEntitys = statisticsDao.selectDaysStatistics(daysQueryRequest);
			for(int i=0;i<23;i++) {
				this.calculateEachQueryRequest(daysQueryRequest, new BigDecimal("1"), 0,i,false);
				UserOperationCurveResponse userOperationCurveResponse = this.handlerAgetUserStatistics(daysQueryRequest);
				list.add(userOperationCurveResponse);
			}
		}else if( days>1 && days<=30) {//每天
			daysQueryRequest.setGroupCondition("0");
			//List<StatisticsEntity> statisticsEntitys = statisticsDao.selectDaysStatistics(daysQueryRequest);
			for(int i=0;i<days;i++) {
				this.calculateEachQueryRequest(daysQueryRequest, new BigDecimal("1"), 1,i,false);
				UserOperationCurveResponse userOperationCurveResponse = this.handlerAgetUserStatistics(daysQueryRequest);
				list.add(userOperationCurveResponse);
			}
		}else if(days>30 && days<=182) {//每周
			daysQueryRequest.setGroupCondition("0");
			int times = (int) (days/7)+1;
			//List<StatisticsEntity> statisticsEntitys = statisticsDao.selectDaysStatistics(daysQueryRequest);
			for(int i=0;i<times;i++) {
				if(i==times-1) {
					this.calculateEachQueryRequest(daysQueryRequest, new BigDecimal("6"), 1,i,true);
				}else {
					this.calculateEachQueryRequest(daysQueryRequest, new BigDecimal("6"), 1,i,false);
				}
				UserOperationCurveResponse userOperationCurveResponse = this.handlerAgetUserStatistics( daysQueryRequest);
				list.add(userOperationCurveResponse);
			}
		}else if(days>182) {//每月
			daysQueryRequest.setGroupCondition("0");
			int times = (int) (days/30)+1;
			//List<StatisticsEntity> statisticsEntitys = statisticsDao.selectDaysStatistics(daysQueryRequest);
			for(int i=0;i<times;i++) {
				if(i==times-1) {
					this.calculateEachQueryRequest(daysQueryRequest, new BigDecimal("29"), 1,i,true);
				}else {
					this.calculateEachQueryRequest(daysQueryRequest, new BigDecimal("29"), 1,i,false);
				}
				UserOperationCurveResponse userOperationCurveResponse = this.handlerAgetUserStatistics( daysQueryRequest);
				list.add(userOperationCurveResponse);
			}
		}
		return list;
	}

	@Override
	public List<OperationResponse> daysAgeBookTotalStatistics(DaysQueryRequest daysQueryRequest) {
		//判断时间是否为天；
		long diff = daysQueryRequest.getQueryEndTime().getTime() - daysQueryRequest.getQueryStartTime().getTime();
		//判断是否真的小于1天
		String dateStartStr = DateFormatUtil.formatDate(daysQueryRequest.getQueryStartTime());
		String dateEndStr = DateFormatUtil.formatDate(daysQueryRequest.getQueryEndTime());
		this.initQueryRequest(daysQueryRequest);
		long days = diff / (1000 * 60 * 60 * 24)+1;  
		if(days<1) {
			if(dateStartStr.equals(dateEndStr)) {
				days = 1;
			}else {
				days = 2;
			}
		}
		daysQueryRequest.setGroupCondition("1");
		List<OperationResponse> operationResponses = new ArrayList<OperationResponse>();
		//各年龄段数据统计
		daysQueryRequest.setQueryEndTime(daysQueryRequest.getOriginalQueryEndTime());
		daysQueryRequest.setOriginalQueryStartTime(daysQueryRequest.getOriginalQueryStartTime());
		
		daysQueryRequest.setMinAge("0");
		daysQueryRequest.setMaxAge("3");
		String daysBorrowUsersAgeVal03 = orderTransDao.daysTotalBorrowBooks(daysQueryRequest);
		OperationResponse dayBorrowUsersAge03 = new OperationResponse();
		dayBorrowUsersAge03.setKey("0-3岁");
		dayBorrowUsersAge03.setValue(daysBorrowUsersAgeVal03);
		operationResponses.add(dayBorrowUsersAge03);
		
		daysQueryRequest.setMinAge("3");
		daysQueryRequest.setMaxAge("6");
		String daysBorrowUsersAgeVal36 = orderTransDao.daysTotalBorrowBooks(daysQueryRequest);
		OperationResponse daysBorrowUsersAge36 = new OperationResponse();
		daysBorrowUsersAge36.setKey("3-6岁");
		daysBorrowUsersAge36.setValue(daysBorrowUsersAgeVal36);
		operationResponses.add(daysBorrowUsersAge36);
		
		daysQueryRequest.setMinAge("6");
		daysQueryRequest.setMaxAge("9");
		String daysBorrowUsersAgeVal69 = orderTransDao.daysTotalBorrowBooks(daysQueryRequest);
		OperationResponse daysBorrowUsersAge69 = new OperationResponse();
		daysBorrowUsersAge69.setKey("6-9岁");
		daysBorrowUsersAge69.setValue(daysBorrowUsersAgeVal69);
		operationResponses.add(daysBorrowUsersAge69);
		
		daysQueryRequest.setMinAge("9");
		daysQueryRequest.setMaxAge("12");
		String daysBorrowUsersAgeVal912 = orderTransDao.daysTotalBorrowBooks(daysQueryRequest);
		OperationResponse daysBorrowUsersAge912 = new OperationResponse();
		daysBorrowUsersAge912.setKey("9-12岁");
		daysBorrowUsersAge912.setValue(daysBorrowUsersAgeVal912);
		operationResponses.add(daysBorrowUsersAge912);
		return operationResponses;
	}

	@Override
	public List<UserOperationCurveResponse> daysBookUserTimeDetailDataStatistics(DaysQueryRequest daysQueryRequest) {
		//判断时间是否为天；
		daysQueryRequest.setQueryStartTime(daysQueryRequest.getOriginalQueryStartTime());
		daysQueryRequest.setQueryEndTime(daysQueryRequest.getOriginalQueryEndTime());
		long diff = daysQueryRequest.getQueryEndTime().getTime() - daysQueryRequest.getQueryStartTime().getTime();
		this.initQueryRequest(daysQueryRequest);
		long days = diff / (1000 * 60 * 60 * 24)+1;  
		daysQueryRequest.setGroupCondition("1");
		List<UserOperationCurveResponse> userOperationCurveResponses = new ArrayList<>();
		for(int i=0;i<days;i++) {
			List<OperationResponse> operationResponses = new ArrayList<OperationResponse>();
			this.caculateTimeDetailEachQueryRequest(daysQueryRequest, i);
			
			daysQueryRequest.setMinAge("0");
			daysQueryRequest.setMaxAge("3");
			String daysBorrowUsersAgeVal03 = orderTransDao.daysTotalBorrowBooks(daysQueryRequest);
			OperationResponse dayBorrowUsersAge03 = new OperationResponse();
			dayBorrowUsersAge03.setKey("0-3岁");
			dayBorrowUsersAge03.setValue(daysBorrowUsersAgeVal03);
			operationResponses.add(dayBorrowUsersAge03);
			
			daysQueryRequest.setMinAge("3");
			daysQueryRequest.setMaxAge("6");
			String daysBorrowUsersAgeVal36 = orderTransDao.daysTotalBorrowBooks(daysQueryRequest);
			OperationResponse daysBorrowUsersAge36 = new OperationResponse();
			daysBorrowUsersAge36.setKey("3-6岁");
			daysBorrowUsersAge36.setValue(daysBorrowUsersAgeVal36);
			operationResponses.add(daysBorrowUsersAge36);
			
			daysQueryRequest.setMinAge("6");
			daysQueryRequest.setMaxAge("9");
			String daysBorrowUsersAgeVal69 = orderTransDao.daysTotalBorrowBooks(daysQueryRequest);
			OperationResponse daysBorrowUsersAge69 = new OperationResponse();
			daysBorrowUsersAge69.setKey("6-9岁");
			daysBorrowUsersAge69.setValue(daysBorrowUsersAgeVal69);
			operationResponses.add(daysBorrowUsersAge69);
			
			daysQueryRequest.setMinAge("9");
			daysQueryRequest.setMaxAge("12");
			String daysBorrowUsersAgeVal912 = orderTransDao.daysTotalBorrowBooks(daysQueryRequest);
			OperationResponse daysBorrowUsersAge912 = new OperationResponse();
			daysBorrowUsersAge912.setKey("9-12岁");
			daysBorrowUsersAge912.setValue(daysBorrowUsersAgeVal912);
			operationResponses.add(daysBorrowUsersAge912);
			
			UserOperationCurveResponse curveResponse = new UserOperationCurveResponse();
			curveResponse.setDateStr(DateFormatUtil.formateDateToString(daysQueryRequest.getQueryStartTime(), DateFormatUtil.DATE_PATTERN_LEAN));
			curveResponse.setOperationResponses(operationResponses);
			userOperationCurveResponses.add(curveResponse);
		}
		return userOperationCurveResponses;
	}
	
	private UserOperationCurveResponse handlerAgeBookStatistics(DaysQueryRequest daysQueryRequest) {List<OperationResponse> operationResponses = new ArrayList<OperationResponse>();
		daysQueryRequest.setMinAge("0");
		daysQueryRequest.setMaxAge("3");
		String daysBorrowUsersAgeVal03 = orderTransDao.daysTotalBorrowBooks(daysQueryRequest);
		OperationResponse dayBorrowUsersAge03 = new OperationResponse();
		dayBorrowUsersAge03.setKey("0-3岁");
		dayBorrowUsersAge03.setValue(daysBorrowUsersAgeVal03);
		operationResponses.add(dayBorrowUsersAge03);
		
		daysQueryRequest.setMinAge("3");
		daysQueryRequest.setMaxAge("6");
		String daysBorrowUsersAgeVal36 = orderTransDao.daysTotalBorrowBooks(daysQueryRequest);
		OperationResponse daysBorrowUsersAge36 = new OperationResponse();
		daysBorrowUsersAge36.setKey("3-6岁");
		daysBorrowUsersAge36.setValue(daysBorrowUsersAgeVal36);
		operationResponses.add(daysBorrowUsersAge36);
		
		daysQueryRequest.setMinAge("6");
		daysQueryRequest.setMaxAge("9");
		String daysBorrowUsersAgeVal69 = orderTransDao.daysTotalBorrowBooks(daysQueryRequest);
		OperationResponse daysBorrowUsersAge69 = new OperationResponse();
		daysBorrowUsersAge69.setKey("6-9岁");
		daysBorrowUsersAge69.setValue(daysBorrowUsersAgeVal69);
		operationResponses.add(daysBorrowUsersAge69);
		
		daysQueryRequest.setMinAge("9");
		daysQueryRequest.setMaxAge("12");
		String daysBorrowUsersAgeVal912 = orderTransDao.daysTotalBorrowBooks(daysQueryRequest);
		OperationResponse daysBorrowUsersAge912 = new OperationResponse();
		daysBorrowUsersAge912.setKey("9-12岁");
		daysBorrowUsersAge912.setValue(daysBorrowUsersAgeVal912);
		operationResponses.add(daysBorrowUsersAge912);
		
		UserOperationCurveResponse curveResponse = new UserOperationCurveResponse();
		curveResponse.setDateStr(DateFormatUtil.formateDateToString(daysQueryRequest.getQueryStartTime(), DateFormatUtil.DATE_PATTERN_LEAN));
		curveResponse.setOperationResponses(operationResponses);
		
		return curveResponse;
	}
	@Override
	public List<UserOperationCurveResponse> daysBookUserEachStatistics(DaysQueryRequest daysQueryRequest) {
		daysQueryRequest.setQueryStartTime(daysQueryRequest.getOriginalQueryStartTime());
		daysQueryRequest.setQueryEndTime(daysQueryRequest.getOriginalQueryEndTime());
		List<UserOperationCurveResponse> list = new ArrayList<>();
		this.initQueryRequest(daysQueryRequest);
		Date queryEndTime = daysQueryRequest.getQueryEndTime();
		Date queryStartTime = daysQueryRequest.getQueryStartTime();
		if(queryStartTime==null) {
			return null;
		}
		long diff = queryEndTime.getTime() - queryStartTime.getTime();
		long days = diff / (1000 * 60 * 60 * 24)+1;  
		if(days<=1) {//直接24小时
			daysQueryRequest.setGroupCondition("1");
			String dateStr = DateFormatUtil.formatDate(daysQueryRequest.getQueryStartTime());
			Date starTime = DateFormatUtil.parseDate(dateStr);
			
			daysQueryRequest.setOriginalQueryStartTime(starTime);
			daysQueryRequest.setQueryStartTime(starTime);
			
			String endDateStr = dateStr+" 23:59:59";
			Date endTime = DateFormatUtil.parseDatePattern(endDateStr, DateFormatUtil.DATETIME_PATTERN);
			daysQueryRequest.setOriginalQueryEndTime(endTime);
			daysQueryRequest.setQueryEndTime(endTime);
			
			//List<StatisticsEntity> statisticsEntitys = statisticsDao.selectDaysStatistics(daysQueryRequest);
			for(int i=0;i<23;i++) {
				this.calculateEachQueryRequest(daysQueryRequest, new BigDecimal("1"), 0,i,false);
				UserOperationCurveResponse userOperationCurveResponse = this.handlerAgeBookStatistics(daysQueryRequest);
				list.add(userOperationCurveResponse);
			}
		}else if( days>1 && days<=30) {//每天
			daysQueryRequest.setGroupCondition("0");
			//List<StatisticsEntity> statisticsEntitys = statisticsDao.selectDaysStatistics(daysQueryRequest);
			for(int i=0;i<days;i++) {
				this.calculateEachQueryRequest(daysQueryRequest, new BigDecimal("1"), 1,i,false);
				UserOperationCurveResponse userOperationCurveResponse = this.handlerAgeBookStatistics(daysQueryRequest);
				list.add(userOperationCurveResponse);
			}
		}else if(days>30 && days<=182) {//每周
			daysQueryRequest.setGroupCondition("0");
			int times = (int) (days/7)+1;
			//List<StatisticsEntity> statisticsEntitys = statisticsDao.selectDaysStatistics(daysQueryRequest);
			for(int i=0;i<times;i++) {
				if(i==times-1) {
					this.calculateEachQueryRequest(daysQueryRequest, new BigDecimal("6"), 1,i,true);
				}else {
					this.calculateEachQueryRequest(daysQueryRequest, new BigDecimal("6"), 1,i,false);
				}
				UserOperationCurveResponse userOperationCurveResponse = this.handlerAgeBookStatistics( daysQueryRequest);
				list.add(userOperationCurveResponse);
			}
		}else if(days>182) {//每月
			daysQueryRequest.setGroupCondition("0");
			int times = (int) (days/30)+1;
			//List<StatisticsEntity> statisticsEntitys = statisticsDao.selectDaysStatistics(daysQueryRequest);
			for(int i=0;i<times;i++) {
				if(i==times-1) {
					this.calculateEachQueryRequest(daysQueryRequest, new BigDecimal("29"), 1,i,true);
				}else {
					this.calculateEachQueryRequest(daysQueryRequest, new BigDecimal("29"), 1,i,false);
				}
				UserOperationCurveResponse userOperationCurveResponse = this.handlerAgeBookStatistics( daysQueryRequest);
				list.add(userOperationCurveResponse);
			}
		}
		return list;
	}

	@Override
	public List<OperationResponse> daysLabelBooksTotalStatistics(DaysQueryRequest daysQueryRequest) {
		//判断时间是否为天；
		long diff = daysQueryRequest.getQueryEndTime().getTime() - daysQueryRequest.getQueryStartTime().getTime();
		//判断是否真的小于1天
		String dateStartStr = DateFormatUtil.formatDate(daysQueryRequest.getQueryStartTime());
		String dateEndStr = DateFormatUtil.formatDate(daysQueryRequest.getQueryEndTime());
		this.initQueryRequest(daysQueryRequest);
		long days = diff / (1000 * 60 * 60 * 24)+1;  
		if(days<1) {
			if(dateStartStr.equals(dateEndStr)) {
				days = 1;
			}else {
				days = 2;
			}
		}
		daysQueryRequest.setGroupCondition("1");
		List<OperationResponse> operationResponses = new ArrayList<OperationResponse>();
		//各主题数据统计
		List<BorrowStatistics> borrowStatistics = orderTransDao.daysLabelTotalBorrowBooks(daysQueryRequest);
		for(BorrowStatistics statistics:borrowStatistics) {
			if(statistics.getTopicalName().equals("全部")) {
				continue;
			}
			OperationResponse operationResponse = new OperationResponse();
			operationResponse.setKey(statistics.getTopicalName());
			operationResponse.setValue(statistics.getBorrowBooks());
			operationResponses.add(operationResponse);
		}
		return operationResponses;
	}

	@Override
	public List<UserOperationCurveResponse> daysLabelBooksTimeDetailDataStatistics(DaysQueryRequest daysQueryRequest) {
		//判断时间是否为天；
		daysQueryRequest.setQueryStartTime(daysQueryRequest.getOriginalQueryStartTime());
		daysQueryRequest.setQueryEndTime(daysQueryRequest.getOriginalQueryEndTime());
		long diff = daysQueryRequest.getQueryEndTime().getTime() - daysQueryRequest.getQueryStartTime().getTime();
		this.initQueryRequest(daysQueryRequest);
		long days = diff / (1000 * 60 * 60 * 24)+1;  
		daysQueryRequest.setGroupCondition("1");
		List<UserOperationCurveResponse> userOperationCurveResponses = new ArrayList<>();
		for(int i=0;i<days;i++) {
			List<OperationResponse> operationResponses = new ArrayList<OperationResponse>();
			this.caculateTimeDetailEachQueryRequest(daysQueryRequest, i);
			
			//各主题数据统计
			List<BorrowStatistics> borrowStatistics = orderTransDao.daysLabelTotalBorrowBooks(daysQueryRequest);
			for(BorrowStatistics statistics:borrowStatistics) {
				if(statistics.getTopicalName().equals("全部")) {
					continue;
				}
				OperationResponse operationResponse = new OperationResponse();
				operationResponse.setKey(statistics.getTopicalName());
				operationResponse.setValue(statistics.getBorrowBooks());
				operationResponses.add(operationResponse);
			}
			
			UserOperationCurveResponse curveResponse = new UserOperationCurveResponse();
			curveResponse.setDateStr(DateFormatUtil.formateDateToString(daysQueryRequest.getQueryStartTime(), DateFormatUtil.DATE_PATTERN_LEAN));
			curveResponse.setOperationResponses(operationResponses);
			userOperationCurveResponses.add(curveResponse);
		}
		return userOperationCurveResponses;
	}
	private UserOperationCurveResponse handlerLabelBooksEachStatistics(DaysQueryRequest daysQueryRequest) {
		List<OperationResponse> operationResponses = new ArrayList<OperationResponse>();
		//各主题数据统计
		List<BorrowStatistics> borrowStatistics = orderTransDao.daysLabelTotalBorrowBooks(daysQueryRequest);
		for(BorrowStatistics statistics:borrowStatistics) {
			if(statistics.getTopicalName().equals("全部")) {
				continue;
			}
			OperationResponse operationResponse = new OperationResponse();
			operationResponse.setKey(statistics.getTopicalName());
			operationResponse.setValue(statistics.getBorrowBooks());
			operationResponses.add(operationResponse);
		}
		
		UserOperationCurveResponse curveResponse = new UserOperationCurveResponse();
		curveResponse.setDateStr(DateFormatUtil.formateDateToString(daysQueryRequest.getQueryStartTime(), DateFormatUtil.DATE_PATTERN_LEAN));
		curveResponse.setOperationResponses(operationResponses);
		
		return curveResponse;
	}
	@Override
	public List<UserOperationCurveResponse> dayLabelBooksEachStatistics(DaysQueryRequest daysQueryRequest) {
		daysQueryRequest.setQueryStartTime(daysQueryRequest.getOriginalQueryStartTime());
		daysQueryRequest.setQueryEndTime(daysQueryRequest.getOriginalQueryEndTime());
		List<UserOperationCurveResponse> list = new ArrayList<>();
		this.initQueryRequest(daysQueryRequest);
		Date queryEndTime = daysQueryRequest.getQueryEndTime();
		Date queryStartTime = daysQueryRequest.getQueryStartTime();
		if(queryStartTime==null) {
			return null;
		}
		long diff = queryEndTime.getTime() - queryStartTime.getTime();
		long days = diff / (1000 * 60 * 60 * 24)+1;  
		if(days<=1) {//直接24小时
			daysQueryRequest.setGroupCondition("1");
			String dateStr = DateFormatUtil.formatDate(daysQueryRequest.getQueryStartTime());
			Date starTime = DateFormatUtil.parseDate(dateStr);
			
			daysQueryRequest.setOriginalQueryStartTime(starTime);
			daysQueryRequest.setQueryStartTime(starTime);
			
			String endDateStr = dateStr+" 23:59:59";
			Date endTime = DateFormatUtil.parseDatePattern(endDateStr, DateFormatUtil.DATETIME_PATTERN);
			daysQueryRequest.setOriginalQueryEndTime(endTime);
			daysQueryRequest.setQueryEndTime(endTime);
			
			for(int i=0;i<23;i++) {
				this.calculateEachQueryRequest(daysQueryRequest, new BigDecimal("1"), 0,i,false);
				UserOperationCurveResponse userOperationCurveResponse = this.handlerLabelBooksEachStatistics(daysQueryRequest);
				list.add(userOperationCurveResponse);
			}
		}else if( days>1 && days<=30) {//每天
			daysQueryRequest.setGroupCondition("0");
			for(int i=0;i<days;i++) {
				this.calculateEachQueryRequest(daysQueryRequest, new BigDecimal("1"), 1,i,false);
				UserOperationCurveResponse userOperationCurveResponse = this.handlerLabelBooksEachStatistics(daysQueryRequest);
				list.add(userOperationCurveResponse);
			}
		}else if(days>30 && days<=182) {//每周
			daysQueryRequest.setGroupCondition("0");
			int times = (int) (days/7)+1;
			for(int i=0;i<times;i++) {
				if(i==times-1) {
					this.calculateEachQueryRequest(daysQueryRequest, new BigDecimal("6"), 1,i,true);
				}else {
					this.calculateEachQueryRequest(daysQueryRequest, new BigDecimal("6"), 1,i,false);
				}
				UserOperationCurveResponse userOperationCurveResponse = this.handlerLabelBooksEachStatistics( daysQueryRequest);
				list.add(userOperationCurveResponse);
			}
		}else if(days>182) {//每月
			daysQueryRequest.setGroupCondition("0");
			int times = (int) (days/30)+1;
			for(int i=0;i<times;i++) {
				if(i==times-1) {
					this.calculateEachQueryRequest(daysQueryRequest, new BigDecimal("29"), 1,i,true);
				}else {
					this.calculateEachQueryRequest(daysQueryRequest, new BigDecimal("29"), 1,i,false);
				}
				UserOperationCurveResponse userOperationCurveResponse = this.handlerLabelBooksEachStatistics( daysQueryRequest);
				list.add(userOperationCurveResponse);
			}
		}
		return list;
	}
}
